Saratov State University :: Online Contester


::Go
- home
- news
- register
- update personal info
- problemset archive
- submit
- status online
- standing
- contests
- virtual contests
- forum
- statistic
- FAQ
- links
- projects

::Poll
Are you registered on Codeforces?
Yes
No
What is it???

[results]

::webboard

WA at test 8
Author: cabinfever
ID: 066995
Problem: 111
Contest: 0
Date: 2015-11-07 14:43:38

I can't find a data that can make my program wrong。
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>

using namespace std;

#define Rep(x,y,z) for(int x=y;x<z;x++)
#define mem(x,y) memset(x,y,sizeof(x))

char s[2010];
int ans[2010],num[2010];
int rem[2010];//remainder
int ls,la=0,lr,ld,lp,tc;
int divv[2010];//divisor
int pro[2010];//product

void Init()
{
return;
}

bool Check()
{
int i=0;
if(lp>lr)
return false;
if(lp<lr)
return true;
while(rem[i]==pro[lp-1-i]&&i<lp)
i++;
if(i==lp)
i=lp-1;
if(rem[i]<pro[lp-1-i])
return false;
else
return true;
}

bool Try()
{
mem(divv,0);
mem(pro,0);
Rep(i,0,la)
{
divv[i+2]=(ans[la-i-1]*2+divv[i+1])/10;
divv[i+1]=(ans[la-i-1]*2+divv[i+1])%10;
}
ld=0;
divv[ld]+=tc;
while(divv[ld]>10)
{
divv[ld]%=10;
divv[++ld]+=1;
}
ld=la+1;
while(divv[ld])
ld++;
lp=ld+1;
Rep(i,0,ld)
{
pro[i+1]=(divv[i]*tc+pro[i])/10;
pro[i]=(divv[i]*tc+pro[i])%10;
}
while(1)
{
if(pro[lp-1]!=0)
{
break;
}
lp--;
}
if(Check())
return true;
else
return false;
}

void ChangeRem()
{
Rep(i,0,lr)
divv[i]=rem[lr-i-1];
Rep(i,0,lr)
{
divv[i]=divv[i]-pro[i];
if(divv[i]<0)
{
divv[i]+=10;
divv[i+1]--;
}
}
while(1)
{
if(divv[lr-1]!=0)
{
break;
}
lr--;
}
Rep(i,0,lr)
rem[i]=divv[lr-i-1];
return;
}

void Calc()
{
int ss=0;
ls=strlen(s);
while(s[ss]=='0')
ss++;
ls-=ss;
if(ls % 2 != 0)
{
num[0]=0;
ls++;
Rep(i,1,ls)
num[i]=s[i-1+ss]-'0';
}
else
Rep(i,0,ls)
num[i]=s[i+ss]-'0';
for(int i=0;i<ls;i+=2)
{
rem[lr]=num[i];
rem[lr+1]=num[i+1];
lr+=2;
if(rem[0]==0&&i==0)
{
lr--;
rem[0]=num[i+1];
}
tc=10;
while(tc--)
{
ans[la]=tc;
if(Try())
{
la++;
ChangeRem();
break;
}
}
}
return;
}

int main()
{
scanf("%s",s);
Init();
Calc();
int p=0;
while(ans[p]==0)
p++;
Rep(i,p,la)
printf("%d",ans[i]);
printf("n");
return 0;
}


see sub-tree reply to that message


::Login
Forgot password?

::News
22.10.12 - The problems from the Southern Subregional Programming Contest 2012 added to the problemset archive (542 - 553).
22.10.12 - After the start of the contest the statements in PDF will be available by the link.
23.10.11 - The problems from the Southern Subregional Programming Contest 2011 added to the problemset archive (530 - 541).

::Counter

Server time: 2017-11-23 06:24:10Online Contester Team © 2002 - 2016. All rights reserved.