北大1006ACM的求助

来源:百度知道 编辑:UC知道 时间:2024/06/06 12:38:28
一道北大ACM题的求助,因为是前面的题,所以应该不是很难,但不知道为什么总是答案错误。
网址是:http://acm.pku.edu.cn/JudgeOnline/problem?id=1006
而我的做法是,答案和它的是一样的,但不知道为什么总是答案错误。请高手来做一下,把代码发上来看看可以吗?谢谢。

#include <iostream>
//#include <fstream>
using namespace std;

const int physical = 23;
const int emotional=28;
const int intellectual=33;
const long total = 21252;

int PriodDays(int p, int e, int i, int d)
{
int n;
long sum;
if( p==0 && e==0 && i==0 )
{
return total-d;
}
for( n=0; ; n++)
{
sum = intellectual*n + i;
if( (sum-e)%emotional == 0)
if( (sum-p)%physical == 0)
if( sum>d && sum>p && sum>e && sum>i)
return sum-d;

}
}

int main()
{
//ifstream infile;
//infile.open("cin.txt");
int p,

if(p==-1 ¦ ¦ e==-1 ¦ ¦ i==-1 ¦ ¦ d==1)
为什么d==1,应该d==-1吧?
你去题目下面那里有个disscu的,有个很简单的方法,那里有人贴了上去,是用中国剩余定理做的.

#include<iostream>
using namespace std;
int main()
{
int a,p,e,i,d,f=0;
while(cin >>p>>e>>i>>d &&( p !=-1||e !=-1||i !=-1||d !=-1))
{

for( a =21252; a >= 0;a--)
{
if( (a+d-p)%23==0&&(a+d-e)%28==0&&(a+d-i)%33==0)break;
else continue;
}
f++;
cout <<"Case " <<f<<": the next triple peak occurs in " <<a<<" days."<<endl;
}

return 0;
}

这也是我以前做的 。还可以用中国剩余定理做

/*Source Code
Problem: 1006 User: Rojay
Memory: 120K Time: 894MS
Language: C++ Result: Accepted
*/
//1006
#include<iostream>

using namespace std;