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 |
我试了N组数据,怎么老是wa啊,谁有官方测试数据么#include<iostream> using namespace std; //k=p+23x=i+28y=e+33z===>23x=28y+i-p&&23x=33z+e-p int xyKey[23*33]; int xzKey[23*28]; int dealxy(int p,int i){//23x=28y+i-p int y=0,count=0; while(y<=23*33){ if (!((28*y+i-p)%23))//x能取整数解 xyKey[count++]=i+28*y; y++; } return count;//这里count是指该不定方程解得个数 } int dealxz(int p,int e){ int z=0,count=0; while(z<=23*28){ if (!((33*z+e-p)%23)) xzKey[count++]=e+33*z; z++; } return count; } int main(){ //freopen("1006.txt","r",stdin); int p,i,e,d; int x=0,y=0,z=0; int cases=0; while(cin>>p>>i>>e>>d,p!=-1&&i!=-1&&e!=-1&&d!=-1){ cases++; if (p==i&&p==e){ cout<<"Case "<<cases<<": the next triple peak occurs in "<<(21252-d)<<" days."<<endl; continue; } int lenxy=dealxy(p,i);//处理后将x有整数解时对应的K值放入数组xyKey int lenxz=dealxz(p,e);//处理后将y有整数解时对应的K值放入数组xzKey bool finded=0; for (int m=0;m<lenxy&&!finded;m++){ //对数组xzKey进行二分搜索 int key=xyKey[m]; int low=0,high=lenxz-1; while(low<=high){ int mid=(low+high)/2; if (xzKey[mid]==key){ int k=key-d; k += 21252; k %= 21252; if( k != 0){ cout<<"Case "<<cases<<": the next triple peak occurs in "<<k<<" days."<<endl; finded=1; break; } else break;//里层循环结束 } if (xzKey[mid]>key) high=mid-1; else low=mid+1; } } if (!finded) cout<<"Case "<<cases<<": the next triple peak occurs in "<<"21252"<<" days."<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator