| ||||||||||
| 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 | |||||||||
超时,怎么办?#include<iostream>
using namespace std;
int main()
{
int N,Z,K,M;
int o,i,w;
w=0;
int m[1000];
while(cin>>N>>Z>>M)
{
for(i=0;i<M;i++)
{ cin>>m[i];
if(i>0&&m[i]<Z)
{ if(m[i]==m[i-1]+1)
w++;
else w=0;
}
}
for(K=w;K<N;K++)
{
i=0;
o=1+K;
while(!(o==Z))
{
if(o>N)
o=o-N;
if(o>m[i])
i++;
if(o==m[i])
break;
if(o<m[i]&&(o+K)>m[i])
i++;
o=o+K;
}
if(o==Z)
{cout<<K<<endl;
break;
}
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator