1006 biorhythms
Posted sweet-ginger-candy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1006 biorhythms相关的知识,希望对你有一定的参考价值。
思路:与求最大公约数基本方法一致。虽然起点不同但终点仍旧一致,起点也可以求出相减为0的情况。
注意:不需要用暴力枚举的方法。我们在进行枚举时筛选。以最小的23进行倍数增长一次试验。
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 using namespace std; 5 int main() 6 int p,i,e,d,count=1; 7 while(true) 8 cin>>p>>i>>e>>d; 9 p%=23;i%=28;e%=33; 10 int t,h=0; 11 if(p==-1) 12 break; 13 while(true) 14 t=p+h++*23; 15 if(t<=d)continue; 16 if((t-i)%28==0&&(t-e)%33==0) 17 //printf("Case %d: the next triple peak occurs in %d days.\n", count++, t - d); 18 cout<<"Case "<<count++<<": the next triple peak occurs in "<<t-d<<" days."<<endl; 19 break; 20 21 22 23 return 0; 24
以上是关于1006 biorhythms的主要内容,如果未能解决你的问题,请参考以下文章