| ||||||||||
| 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 | |||||||||
1006问题的严肃问题为什么这段代码在实践中可以得到正确结果,但是却会有wrong answer的宿命?
小弟第一次来,请各位伟人帮助!
#include <iostream>
#include <vector>
using namespace std;
const int p_cycle=23,e_cycle=28,i_cycle=33;
inline void calc(int p, int e, int i, int d)
{
static int nth=0;
nth++;
p%=p_cycle;
e%=e_cycle;
i%=i_cycle;
int first;
for(int ne=1;ne<=p_cycle*i_cycle;ne++)
for(int np=1;np<=e_cycle*i_cycle;np++)
if(e+ne*e_cycle==p+np*p_cycle)
for(int ni=1;ni<=e_cycle*p_cycle;ni++)
if(p+np*p_cycle==i+ni*i_cycle)
{first=p+np*p_cycle;break;}
cout<<"Case "<<nth
<<": the next triple peak occurs in "<<first-d
<<" days.\n";
}
int main()
{
int acount=0;
int p,e,i,d;
vector<int> data;
while(1)
{
cin>>p>>e>>i>>d;
if(p==-1&&e==-1&&i==-1&&d==-1)break;
acount++;
data.push_back(p);
data.push_back(e);
data.push_back(i);
data.push_back(d);
}
int x;
for (int n=0;n<acount;n++)
{
x=n<<2;
calc(data[x],data[x+1],data[x+2],data[x+3]);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator