POJ 2977 生理周期 解题报告

POJ 2977 生理周期 解题报告

编号:2977

 

考查点:枚举

 

思路:之所以是枚举而不是穷举,原则是在循环的层数和循环的次数上进行优化,此题先找出符合p的,再根据这个作循环变量增加条件,继续即可找出符合题意的数字.

 

提交情况: 是按书上的思路AC的,这道题算是半道水题吧,代码很短,但是我试了一种效率较低的算法:每次+33的方法,一直WA,到现在还没想明白。

 

Source Code

 


//POJ Grids 2977
#include <string.h>
#include 
<iostream>
using namespace std;

int main()
{
    
int count = 0;
    
while (++count)
    {
        
int p,e,i,d;
        cin
>>p>>e>>i>>d;
        
if (p==-1)
            
break;
        
int j = d+1;
        
for (;j<21252;j++)
            
if ((j-p)%23==0break;
        
for (;j<21252;j+=23)
            
if ((j-e)%28==0break;
        
for (;j<21252;j=j+23*28)
            
if ((j-i)%33==0break;

        cout
<<"Case "<<count<<": the next triple peak occurs in "<<j-d<<" days."<<endl;
    }
    
return 0;
}

总结:做题要认真,做一道懂一道最好,表眼高手低.

 

 

 

                                                       By   Ns517

                                                      Time 09.02.03

posted @ 2009-02-03 18:37  端木  阅读(879)  评论(2编辑  收藏  举报