标签:sam noi 结束 bsp 如何 space poj 结果 复数
题目链接:
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 0 0 0 0 100 5 20 34 325 4 5 6 7 283 102 23 320 203 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 #include <iostream> 2 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<<k-d<<endl; 15 cout << "Case " << caseNo <<": the next triple peak occurs in " << k-d << " days." << endl; 16 } 17 return 0; 18 }
标签:sam noi 结束 bsp 如何 space poj 结果 复数
原文地址:http://www.cnblogs.com/huashanqingzhu/p/7279101.html