Biorhythms ACM PKU http://acm.pku.cn/JudgeOnline/problem?id=1006

本题可以参考Wikipedia上线性同余同方程的解法,方法很简单手算一会就出来了。

也可以参考中国同余定理;就这么多,下面我展示我的代码:

#include <iostream>
using namespace std;
int main ()
{
int p,e,i,d;
for (int n=1;;n++)
{
   cin >>p>>e>>i>>d;
   int sum,sum1,sum2,sum3;
   if (p==-1&&e==-1&&i==-1&&d==-1)
    break;
   sum1=p;
   sum2=e;
   sum3=i;
     for (int j=1;;j++)
   {
    if ((sum1+23*j-sum2)%28==0&&(sum1+23*j-sum3)%33==0)
    {
     sum=sum1+23*j;
     break;
    }
   }
   if ((21252+sum-d)%21252!=0)
   cout<<"Case "<<n<<": the next triple peak occurs in "<<(21252+sum-d)%21252<<" days."<<endl;
   else 
   cout<<"Case "<<n<<": the next triple peak occurs in "<<21252<<" days."<<endl;

}
return 0;
}

posted on 2011-05-06 19:36  _Clarence  阅读(108)  评论(0编辑  收藏  举报

导航