我的poj 1006Time Limit Exceeded

来源:百度知道 编辑:UC知道 时间:2024/05/12 06:28:20
哪位高手指教一下,那需要改进,为什么超时阿?
#include<iostream.h>

void main()
{

int p,e,i,d,s=0;
int n=1;
int t=1;
while(1)
{
cin>>p>>e>>i>>d;
while(!(p==-1&&e==-1&&i==-1))
{
s=23*t+p;
if(s>21252)
s=s%21252;
if(((s-e)%28==0 )&& ((s-i)%33==0))
{
cout<<"Case"<<" "<<n<<": the next triple peak occurs in "<<s-d<<"days"<<endl;
n++;
break;

}
else t++;

}
}

}

while(1)
{
cin>>p>>e>>i>>d;

改成
while(cin>>p>>e>>i>>d;)
{

其实不用这么麻烦,剩余定理直接出来了
#include <stdio.h>
int main()
{
int q,a,b,c,r,Days=0;
while(1)
{
scanf("%d%d%d%d",&q,&a,&b,&c);
if(q==-1&&a==-1&&b==-1&&c==-1)break;
r=(5544*q+14421*a+1288*b-c+21252)%21252;
if(!r)r=21252;
printf("Case %d: the next triple peak occurs in %d days.\n",++Days,r);
}
return 0;
}

做poj的兄弟握下手. 我排着队做OJ, 现在还没做到poj呢.

你那个while(!(p==-1&&e==-1&&i==-1)) 好像跳不出来啊...

你输入的什么会超时呀?