Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:BlessAladdin,实在不好意思,我有点问题想请教一下的。又引起我的怀疑的。。。。。

Posted by HW at 2005-08-01 03:39:14 on Problem 2514
In Reply To:Re:BlessAladdin,实在不好意思,我有点问题想请教一下的。又引起我的怀疑的。。。。。 Posted by:HW at 2005-08-01 03:34:47
> 
> AC:
> ----------------------------------------
> #include <stdio.h>
> #include <string.h>
> #include <math.h>
> #define maxn 100
> #define maxSave 20
> #define maxSave1 11
> 
> unsigned long long save[maxn][2];
> unsigned long long save1[maxn][2];
> 
> int check(double t,int k){
>   char ch[200];
>   sprintf(ch,"%.0lf",t);
>   return ch[k]-'0';
> }
> 
> void buildSave(){
>   unsigned long long k=1;
>   unsigned long long i;
> 
>   for (i=10;k<maxSave;i*=10){
>     save[k][0]=(unsigned long long)sqrtl((long double)(i-1));
>     save[k][1]=(save[k][0]-save[k-1][0])*k+save[k-1][1];
>     k++;
>   }
>   
>   k=1;
>   save1[0][0]=save1[0][1]=0;
>   for (i=10;k<maxSave1;i*=10){
>     save1[k][1]=save1[k-1][1]+(i-(i/10))*k;
>     save1[k][0]=i-1;
>     k++;
>   }
> }
> 
> int findSave(unsigned long long k){
>   unsigned long long i,t,u;
>   double tem;
>   for (i=0;;i++)
>     if (k<=save[i+1][1]){t=i+1; break;}
>   u=(k-save[t-1][1]+(t-1))%t;
>   k=(k-save[t-1][1]+(t-1))/t;
>   k=k+save[t-1][0];
>   tem=(double)k;
>   tem*=tem;
>   return check(tem,u);
> }
> 
> int findSave1(unsigned long long k){
>   unsigned long long i,t,u;
>   for (i=0;;i++)
>     if (k<=save1[i+1][1]){t=i+1; break;}
>   u=(k-save1[t-1][1]+(t-1))%t;
>   k=(k-save1[t-1][1]+(t-1))/t+save1[t-1][0];
>   return check(k,u);
> }
> 
> int main(){
>   unsigned long long t,i;
>   int s[1000],s1[1000],k;
>   buildSave();
>   while (scanf("%lld",&t) && t>0){
>     k=0;
>     s[k]=findSave(t);
>     s1[k]=findSave1(t);
>     k++;
>     
>     for (i=t+1;;i++){
>       s[k]=findSave(i);
>       s1[k]=findSave1(i);
>       if (s[k]+s1[k]<9 || s[k]+s1[k++]>=10) break;
>     }
>     
>     for (i=k-1;i>=1;i--)
>       s[i-1]=(s[i]+s1[i])/10+s[i-1];
>     printf("%d\n",(s[0]+s1[0])%10);
>   }
>   return 0;
> }
> --------------------------------------------------------
> 
> WA:
> --------------------------------------------------------
> #include <stdio.h>
> #include <string.h>
> #include <math.h>
> #define maxn 100
> #define maxSave 20
> #define maxSave1 11
> 
> unsigned long long save[maxn][2];
> unsigned long long save1[maxn][2];
> 
> int check(unsigned long long t,int k){
            ~~~~~~~~~~~~~~~~~~~~
>   char ch[200];
>   sprintf(ch,"%lld",t);
               ~~~~~~~
>   return ch[k]-'0';
> }
> 
> void buildSave(){
>   unsigned long long k=1;
>   unsigned long long i;
> 
>   for (i=10;k<maxSave;i*=10){
>     save[k][0]=(unsigned long long)sqrtl((long double)(i-1));
>     save[k][1]=(save[k][0]-save[k-1][0])*k+save[k-1][1];
>     k++;
>   }
>   
>   k=1;
>   save1[0][0]=save1[0][1]=0;
>   for (i=10;k<maxSave1;i*=10){
>     save1[k][1]=save1[k-1][1]+(i-(i/10))*k;
>     save1[k][0]=i-1;
>     k++;
>   }
> }
> 
> int findSave(unsigned long long k){
>   unsigned long long i,t,u;
>   for (i=0;;i++)
>     if (k<=save[i+1][1]){t=i+1; break;}
>   u=(k-save[t-1][1]+(t-1))%t;
>   k=(k-save[t-1][1]+(t-1))/t;
>   k=k+save[t-1][0];
>   return check(k*k,u);
                 ~~~~
> }
> 
> int findSave1(unsigned long long k){
>   unsigned long long i,t,u;
>   for (i=0;;i++)
>     if (k<=save1[i+1][1]){t=i+1; break;}
>   u=(k-save1[t-1][1]+(t-1))%t;
>   k=(k-save1[t-1][1]+(t-1))/t+save1[t-1][0];
>   return check(k,u);
> }
> 
> int main(){
>   unsigned long long t,i;
>   int s[1000],s1[1000],k;
>   buildSave();
>   while (scanf("%lld",&t) && t>0){
>     k=0;
>     s[k]=findSave(t);
>     s1[k]=findSave1(t);
>     k++;
>     
>     for (i=t+1;;i++){
>       s[k]=findSave(i);
>       s1[k]=findSave1(i);
>       if (s[k]+s1[k]<9 || s[k]+s1[k++]>=10) break;
>     }
>     
>     for (i=k-1;i>=1;i--)
>       s[i-1]=(s[i]+s1[i])/10+s[i-1];
>     printf("%d\n",(s[0]+s1[0])%10);
>   }
>   return 0;
> }
> --------------------------------------------------------

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator