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:34:47 on Problem 2514
In Reply To:BlessAladdin,实在不好意思,我有点问题想请教一下的。又引起我的怀疑的。。。。。 Posted by:HW at 2005-08-01 03:15:42
> 我的程序已经AC了,不过是把精度放低了,放到double才过了,用long long是过不了的
> 
> 问题还是我之前说的那个,精度不够高
> 我用了
> time ./a3
> 
> real    433m0.787s
> user    430m48.242s
> sys     0m21.187s
> 
> 433分钟把我同学的那个AC的程序(把精度改成long long之后的),从1到2^31-1的所有数据都跑了一次,全部和我的程序都一样的
> 我把那个程序的精度改成long long后再提交也过不了了,改成double就过了。
> 
> 我自己的程序也是一样的。
> 
> 我现在又再一次,怀疑测试用的数据有不对的地方了,不是指你的程序有问题。
> 你能帮忙看看是什么问题吗?有可能是数据的问题吗?

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