poj 1006

#include <iostream>
#include <vector>
int main()
{
	std::vector< std::vector<int> > vi;
	while(1)
	{
		std::vector<int> vl(4);
		std::cin>>vl[0]>>vl[1]>>vl[2]>>vl[3];
		if(vl[0]==-1 && vl[1]==-1 && vl[2]==-1 && vl[3]==-1)
			break;
		vi.push_back(vl);
	}
	for(unsigned int i=0; i<vi.size(); i++)
	{
		int day = 1;
		if(vi[i][3]>day)
			day = vi[i][3];
		int dmax = 21252+vi[i][3];
		for(; day<=dmax; day++)
		{
			if((day%23-vi[i][0]%23)==0 && (day%28-vi[i][1]%28)==0 && (day%33-vi[i][2]%33)==0){
				std::cout<<"Case "<<i+1<<": the next triple peak occurs in "<<day-vi[i][3]<<" days.\n";
				break;
			}
		}
	}
	return 0;
}


这题提交了4次,前3次都是Wrong answer,后来继续看题,发现每次前三个值不一定比第四个小,且不一定是每年的第一个高峰值,修改if判断逻辑,通过

性能:

1    452515        moonancient    4K    0MS    Pascal    350B     2005-05-06 02:49:41
2    495174(5)    oliverzhou    4K    0MS    Pascal    551B     2005-06-17 12:13:07
3    2383621        040824108    8K    0MS    C++    311B     2007-07-24 17:39:25

16934    11110763    dragoo1    1006    272K    360MS    C++    652B    2012-12-15 14:50:26

你可能感兴趣的:(poj 1006)