QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#135745#5460. Sum of NumberslinninsCompile Error//C++141.9kb2023-08-05 23:32:262023-08-05 23:32:29

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-05 23:32:29]
  • 评测
  • [2023-08-05 23:32:26]
  • 提交

answer

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

char Mid[200500];
int Map[200500];

int Ans[200500];
int Sum[200500];

int Anspoint = 2147483647;
int Sumpoint = 0;

void ADD(int p,int n)
{
	for(int i=1;i<=n;i++)
	{
		Sum[i] += Map[p+i];
	}
	Sumpoint = max(Sumpoint,n);
}

void clearSum(int n)
{
	int flag = Sumpoint;
	for(int i=1;i<Sumpoint;i++)
	{
		Sum[i+1] += Sum[i]/10;
		Sum[i] %= 10; 
	}
	while(Sum[flag]>10)
	{
		Sum[flag+1] = Sum[flag]/10;
		Sum[flag]%=10;
		flag+=1;
		Sumpoint = flag;
	}

}

void change()
{
	Anspoint = Sumpoint;
	for(int i=1;i<=Sumpoint;i++)
	{
		Ans[i] = Sum[i];
	}
}

void updateAns()
{
	if(Anspoint>Sumpoint)
	{
		change();
	}
	else if(Anspoint==Sumpoint)
	{
		for(int i=Anspoint;i>=1;i--)
		{
			if(Ans[i]>Sum[i])
			{
				change();
				break;
			}
			else if(Ans[i] < Sum[i])
				break;
		}
	}
}

int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int n,k;
		Anspoint = 2147483647;
		scanf("%d%d",&n,&k);
		k+=1;
		scanf("%s",Mid);
		int len = strlen(Mid);
		for(int i=len;i>=1;i--)
		{
			Map[i] = Mid[len-i] - '0';
		}
		int avg = n/k;
		int type = pow(3,k+1);
		type -= 1;
		
		for(int i = type;i>=0;i--)
		{
			int MID = i;
			int Sumn = 0;
			Sumpoint = 0;
			for(int i=1;i<=avg+1;i++)
			{
				Sum[i] = 0;
			}
			for(int j=1;j<=k;j++)
			{
				if(MID%3 == 2)
				{
					ADD(Sumn,avg-1)
					Sumn+=avg-1;
				}
				if(MID%3 == 1)
				{
					ADD(Sumn,avg+1);
					Sumn+=avg+1;
				}
				else
				{
					ADD(Sumn,avg);
					Sumn+=avg;
				}
				MID/=2;
				if(Sumn == n)
				{
					clearSum(n);
					updateAns();
				}
			}

		}
		for(int i=Anspoint;i>=1;i--)
		{
			printf("%d",Ans[i]);
		}
		printf("\n");
		
	}
}

/*
20
10 2
2156345972

20
14 3
32154512561264

20
14 6
12345678910354

*/

Details

answer.code: In function ‘int main()’:
answer.code:106:56: error: expected ‘;’ before ‘Sumn’
  106 |                                         ADD(Sumn,avg-1)
      |                                                        ^
      |                                                        ;
  107 |                                         Sumn+=avg-1;
      |                                         ~~~~            
answer.code:76:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   76 |         scanf("%d",&T);
      |         ~~~~~^~~~~~~~~
answer.code:81:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   81 |                 scanf("%d%d",&n,&k);
      |                 ~~~~~^~~~~~~~~~~~~~
answer.code:83:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   83 |                 scanf("%s",Mid);
      |                 ~~~~~^~~~~~~~~~