博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 1006 Biorhythms
阅读量:4484 次
发布时间:2019-06-08

本文共 3595 字,大约阅读时间需要 11 分钟。

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 143771   Accepted: 46262

Description

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. 

Input

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.

Output

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.

Sample Input

0 0 0 00 0 0 1005 20 34 3254 5 6 7283 102 23 320203 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.

Source

思路:简单的模拟。
#include
#include
#include
#include
#define MAXN 21252 using namespace std;int p,e,i,d,ca=1;int main(){ while(scanf("%d%d%d%d",&p,&e,&i,&d)&&p!=-1&&e!=-1&&i!=-1&&d!=-1){ int r1=23,r2=28,r3=33; int re1=r2*r3,re2=r1*r3,re3=r1*r2,re=r1*r2*r3; int res1=re1,res2=re2,res3=re3; while(res1%r1!=1) res1+=re1; while(res2%r2!=1) res2+=re2; while(res3%r3!=1) res3+=re3; res1*=p;res2*=e;res3*=i; int k=re; while(res1+res2+res3>k) k+=re; k-=re; int t=(res1+res2+res3-k-d+MAXN)%MAXN; if(t==0) printf("Case %d: the next triple peak occurs in %d days.\n",ca++,21252); else printf("Case %d: the next triple peak occurs in %d days.\n",ca++,t); }}

 

转载于:https://www.cnblogs.com/cangT-Tlan/p/8832134.html

你可能感兴趣的文章
AspNet Core 发布到Linux系统和发布IIS 注意项
查看>>
Windows添加.NET Framework 3.0 NetFx3 失败 - 状态为:0x800f0950
查看>>
隐藏显示终端的光标(shell echo,linux c printf)
查看>>
SQL Server 存储过程
查看>>
JSP 标准标签库(JSTL)(JSP Standard Tag Library)
查看>>
导入项目遇到的问题: Some projects cannot be imported because they already exist in the workspace....
查看>>
华为:字符集合
查看>>
用Okhttp框架登录之后的Cookie设置到webView中(转)
查看>>
Java_Activiti5_菜鸟也来学Activiti5工作流_之入门简单例子(一)
查看>>
elasticsearch 5.x 系列之二 线程池的设置
查看>>
Java入门系列:实例讲解ArrayList用法
查看>>
洛谷P1080 国王游戏【大数】【贪心】
查看>>
设计模式(一)工厂模式Factory(创建型)
查看>>
Python之匿名函数
查看>>
PhoneGap 3.0 安装
查看>>
每天一个小算法(2)----合并两个有序链表
查看>>
IOS开发把一个结构体放到数组中
查看>>
cglib动态代理(即AOP)
查看>>
linux中安装软件的集中方法
查看>>
Express中间件,看这篇文章就够了(#^.^#)
查看>>