题解 | #Biorhythms#

Biorhythms

https://www.nowcoder.com/practice/aa66f85934c142f3af2da111dc864d9f

利用甘特图好理解些
|	| 23
|		| 28
|			| 33
保持两段不动,有一段(比如23)一直增加自身长度,当23*x减去28(33)剩余的还是28的整数倍,说明峰值重合。
|


#include<iostream>
using namespace std;
int main()
{
    int date;
    int p,e,i,d;
    cin>>p>>e>>i>>d;
    int count=0;
    int k=0;
    while(1)
    {  //甘特图
        e=e+28;
        k++;
        if((e-p)%23==0&&(e-i)%33==0&&e>d)
        {
            date=e-d;
            cout<<"Case: the next triple peak occurs in "<<date<<" days.";
            break;
        }

    }

}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务