Biorhythms_余数定理

题目描述

    Some people believe that there are three cycles in a person's life that start the day he or she is born. These three cycles are the physical, emotional, and intellectual cycles, and they have periods of lengths 23, 28, and 33 days, respectively. There is one peak in each period of a cycle. At the peak of a cycle, a person performs at his or her best in the corresponding field (physical, emotional or mental). For example, if it is the mental curve, thought processes will be sharper and concentration will be easier. Since the three cycles have different periods, the peaks of the three cycles generally occur at different times. We would like to determine when a triple peak occurs (the peaks of all three cycles occur in the same day) for any person. For each cycle, you will be given the number of days from the beginning of the current year at which one of its peaks (not necessarily the first) occurs. You will also be given a date expressed as the number of days from the beginning of the current year. You task is to determine the number of days from the given date to the next triple peak. The given date is not counted. For example, if the given date is 10 and the next triple peak occurs on day 12, the answer is 2, not 3. If a triple peak occurs on the given date, you should give the number of days to the next occurrence of a triple peak.

输入描述:

    You will be given a number of cases. The input for each case consists of one line of four integers p, e, i, and d. The values p, e, and i are the number of days from the beginning of the current year at which the physical, emotional, and intellectual cycles peak, respectively. The value d is the given date and may be smaller than any of p, e, or i. All values are non-negative and at most 365, and you may assume that a triple peak will occur within 21252 days of the given date.

输出描述:

    Case: the next triple peak occurs in 1234 days.
    Use the plural form "days'' even if the answer is 1.
示例1

输入

复制
0 0 0 0

输出

复制
Case: the next triple peak occurs in 21252 days.

//找到三个周期的最小公倍数,然后求出与d的距离

可以直接枚举,暴力

//即N+d=23*N1+p=28*N2+e=33*N3+i;题目要求求解的是N

找到一个数模23余数为p,模28余数为e,模33余数为i;使用中国剩余定理

除以23余1,整除28,整除33的三个条件的最小数,发现是5544。

然后求满足  除以28余1,整除23,整除33的三个条件的最小数,是14421。

然后求满足  除以33余1,整除23,整除28的三个条件的最小数,是1288。

然后5544*p+14421*e+1288*i就一定是三个周期的下一个巅峰了,只不过不一定是最小值。最后模最小公倍数就是最小值。

#include<iostream>
using namespace std;
int main(){
	int p,e,i,d,N=0;
	int days;
	while(cin>>p>>e>>i>>d){
		if(p==-1&&e==-1&&i==-1&&d==-1)
		break;
		days=(p*5544+e*14421+i*1288)%21252;
		 if(days-d<=0)
   			days+=21252;
		cout<<"Case: the next triple peak occurs in "<<days-d<<" days."<<endl;
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值