本文共 1598 字,大约阅读时间需要 5 分钟。
题目链接:
poj 1006 http://poj.org/problem?id=1006
NOI题库 http://noi.openjudge.cn/ch0201/1978/
Time Limit: 1000MS Memory Limit: 10000K
Description
Input
Output
Sample Input
0 0 0 00 0 0 1005 20 34 3254 5 6 7283 102 23 320203 301 203 40-1 -1 -1 -1
Sample Output
Case 1: the next triple peak occurs in 21252 days.Case 2: the next triple peak occurs in 21152 days.Case 3: the next triple peak occurs in 19575 days.Case 4: the next triple peak occurs in 16994 days.Case 5: the next triple peak occurs in 8910 days.Case 6: the next triple peak occurs in 10789 days.
解题思路:
来源:北大郭炜老师。
从d+1天开始,一直试到第21252 天,对其中每个日期k,看是否满足 (k – p)%23 == 0 && (k – e)%28 == 0 &&(k-i)%33 == 0 如何试得更快? 跳着试!
1 #include2 using namespace std; 3 #define N 21252 4 int main() 5 { 6 int p,e,i,d,caseNo = 0; 7 while( cin >> p >> e >>i >>d && p!= -1) 8 { 9 caseNo++ ;10 int k;11 for(k = d+1; (k-p)%23; ++k);12 for(; (k-e)%28; k+= 23);13 for(; (k-i)%33; k+= 23*28);14 //cout< <
转载地址:http://qpgjx.baihongyu.com/