| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
救命啊!!!WA了12次的题目,请问问题出哪里了?请问一下有什么特别麻烦的测试数据,我测试过下面的数据没问题,但依然WA
10 100
5
123456789 987654321
4
1 999……99(100个)
479
0 1
1
0 3
3
1 2
2
1 3
3
5 8
2
8 13
2
8 12
1
13 21
2
14 20
0
0 0
帮个忙啊~~~
#include <stdio.h>
#include <string.h>
#define N 150
int len=1,str[N]={0},d=2;
struct
{
int m[N] ;
}fib[490]={0};
int main()
{
int sum(int c[],int a[],int b[],int lenstr);
int check(int a[],int b[],int lena,int lenb);
int search_right(int m[],int len);
int search_left(int m[],int len);
char n[N]={0};
int left[N]={0},right[N]={0};
int i,j=0,lenl,lenr,pleft,pright;
fib[0].m[0]=1;fib[0].m[149]=0;str[0]=0;
fib[1].m[0]=1;fib[1].m[149]=1;str[1]=1;
for(i=2;i<=480;i++)
{sum(fib[i].m,fib[i-1].m,fib[i-2].m,len);d++;} //结构体相加求FIBS
while(1)
{
scanf("%s",&n);
lenl=strlen(n);
for(i=0;i<lenl;i++)
left[i]=n[lenl-i-1]-48;
scanf("%s",&n);
lenr=strlen(n);
if(n[0]=='0') break;
for(i=0;i<lenr;i++)
right[i]=n[lenr-i-1]-48;
pleft=search_left(left,lenl);
pright=search_right(right,lenr);
printf("%d\n",pright-pleft);
}
return 0;
}
int sum(int c[],int a[],int b[],int lenstr) //高精度加法
{
int i;
for(i=0;i<=lenstr;i++)
{
if((a[i]+b[i]+c[i])<10) c[i]=a[i]+b[i]+c[i];
else {c[i]=a[i]+b[i]+c[i]-10;c[i+1]++;}
}
if(c[lenstr]==1) {len=lenstr+1;str[len]=d;} //STR[]保存进位时N,方便字典搜索
c[149]=len; //C[149]保存数据长度
return 0;
}
int check(int a[],int b[],int lena,int lenb) //检查两数大小
{
int i;
if(lena>lenb) return 0;
else if(lena<lenb) return 1;
else
{
for(i=lena-1;i>=0;i--)
{
if(a[i]>b[i]) return 0;//big
else if(a[i]<b[i]) return 1;//small
}
}
return 2;//equal
}
int search_left(int a[],int len)
{ //搜索小于左边界
int i;
for(i=str[len]-1;i<=str[len+1];i++)
{
if(check(a,fib[i].m,len,fib[i].m[149])==1) return i-1;
if(check(a,fib[i].m,len,fib[i].m[149])==2) return i-1;
}
}
int search_right(int a[],int len) //搜索小于等于有右边界
{
int i;
for(i=str[len]-1;i<=str[len+1];i++)
{
if(check(a,fib[i].m,len,fib[i].m[149])==1) return i-1;
if(check(a,fib[i].m,len,fib[i].m[149])==2) return i;
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator