题目描述:
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. The end of input is indicated by
a line in which p = e = i = d = -1.
输出:
For each test case, print the case number followed by a message indicating the number of days to the next triple peak, in the form:
Case 1: the next triple peak occurs in 1234 days.
Use the plural form "days'' even if the answer is 1.
样例输入:
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
样例输出:
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.
简单的来说,就是求一个最小的数X。使得 X % 23 = p; X % 28 = e; X % 33 = i;
这就是著名的中国剩余定理。
数学上的常规解法是这样的:
找到一个找到一个自然数t,使得 (e*i) * t % 23 = p .这里的t要从1开始试。 令 a =(e*i) * t
再依次找到 b,c。 a+b+c则符合条件。
编程中,有一个更简便的方法。
找到一个数使得X , 使得 X % (e * i) = 1; (可使用上面的方法一个一个试)。
则 X * p % (e * i) = p;
代码如下:
5544 % 23 = 1; 5544 % (28 * 33) = 0;
#include <stdio.h>
int main()
{
int p, e, i, n, sum, t;
t = 0;
while (scanf("%d%d%d%d", &p, &e, &i, &n), p + e + i + n != -4)
{
sum = (5544 * p + 14421 * e + 1288 * i) % 21252;
if (sum - n <= 0)
sum += 21252;
printf("Case %d: the next triple peak occurs in %d days.\n", ++t,
sum - n);
}
return 0;
}
分享到:
相关推荐
使用vs2010编写,直接用vs2010打开加压后的.sln文件即可看到...九度OJ上面的剑指Offer习题全套答案,全部AC,且具有较好的时间复杂度。部分参考网络上的idea,但代码已经尽量要求简洁,是OJ练习不可多得的参考代码。
九度智能seo优化软件是一款针对搜索引擎的点击类软件。软件适用于百度、谷歌、360搜索、搜狗、搜搜、淘宝、天猫等等搜索引擎,可以用来提高...绝对是专业人士必备的seo优化软件,您值得拥有! 九度智能seo优化软件截图
完整可以用在二次开发,节约时间成本,
由于九度搜索点击软件完全模仿人的自然行为进行点击,所以软件工作时,占用一台电脑,在挂机的同时,不能干其他的事情。建议在闲暇时挂机,或有多余的电脑挂机,也可以在自己的电脑上,安装虚拟机,在虚拟机上运行...
这是九度OJ-题目1509:树中两个结点的最低公共祖先的测试数据,input.txt是输入数据,output.txt是输出数据。
九度 ACM 很好的九度 ACM解题报告 不错 大家可以下下来看看 九度内推
由于九度搜索点击软件完全模仿人的自然行为进行点击,所以软件工作时,占用一台电脑,在挂机的同时,不能干其他的事情。建议在闲暇时挂机,或有多余的电脑挂机,也可以在自己的电脑上,安装虚拟机,在虚拟机上运行...
九度OJ八皇后问题,主要是主对角线和副对角线的判断上面优化。在九度1140上面已经AC
资源分享者,资源爱好者,我是浪杉,点我资料关注,每日不定时分享全网优质源码!
ZJU考研机试真题 九度1006ZOJ问题
九度智能SEO优化软件是九度搜索引擎点击优化软件重新开发版,本是针对搜索引擎的SEO优化类软件,2016年10月正式上线。软件可像真人点击一样,自动点击百度、谷歌、360搜索、搜狗、搜搜、淘宝、天猫等搜索引擎内的...
九度求职经验系列之“实习生”篇.pdf 讲述了九度求职经验相关内容
由于九度搜索点击软件完全模仿人的自然行为进行点击,所以软件工作时,占用一台电脑,在挂机的同 时,不能干其他的事情。建议在闲暇时挂机,或有多余的电脑挂机,也可以在自己的电脑上,安装虚拟机,在虚拟机上运行...
ZJU考研机试真题 九度1004Median
九度算法实现EXCEL排序 Excel可以对一组纪录按任意指定列排序。现请你编写程序实现类似功能。 对每个测试用例,首先输出1行“Case i:”,其中 i 是测试用例的编号(从1开始)。随后在 N 行中输出按要求排序后的结果...
ThinkPhp个人真是没研究明白,有懂行的技术过硬的可以下载看看,如果好用就赚了。
九度oj 题目1369:字符串的排列 剑指offer里面的题目 自己写的代码,供参考!
计算机机试指南九度OJ机试题目解析复试机试参考,适用于计算机考研的同学,文档整理汇总了各个分类,方便入门和刷题参考。
conn.asp 数据连接修改,站点名称和网址 del.asp 数据删除页,密码在文件里面修改 xg.mdb 数据库