Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 135099   Accepted: 43146

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 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

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. 题目长,题意是:给出 p,e,i,d ,已知 (n+d)%23 == p ,(n+d)%28 == e , (n+d)%33 == i ,求 n (N>0)
暴力即可,写一下记录中国剩余定理,又名孙子定理

解法:
已知(n+d)%23=p; (n+d)%28=e; (n+d)%33=i
使28×33×a被23除余1,用33×28×8=5544;
使23×33×b被28除余1,用23×33×19=14421;
使23×28×c被33除余1,用23×28×2=1288。
所以:(5544×p+14421×e+1288×i)% lcm(23,28,33) = n+d
23、28、33互质,即lcm(23,28,33)= 21252;

得式子:n=(5544×p+14421×e+1288×i-d+lcm)%lcm

其实也就是凑出来这个数字

暴力的:

 #include <iostream>
#include <stdio.h> using namespace std;
#define MAX 21252 int main()
{
int a,b,c,d;
int cas=;
while (scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF)
{
if (a==-&&b==-&&c==-&&d==-)
break;
a%=;
b%=;
c%=;
for (int i=c;i<=MAX+;i+=)
{
if ((i-a)%== && (i-b)%== && (i-c)%==)
{
if (i<=d)
i+=MAX;
printf("Case %d: the next triple peak occurs in %d days.\n",cas++,i-d);
break;
}
}
}
return ;
}

定理的: 快一些

 #include <iostream>
#include <stdio.h>
using namespace std; int main()
{
int p,e,i,d;
int cas=;
while (scanf("%d%d%d%d",&p,&e,&i,&d)!=EOF)
{
if (p==-&&e==-&&i==-&&d==-) break; int n=(*p+*e+*i-d+)%;
if (n==) n+=;
printf("Case %d: the next triple peak occurs in %d days.\n",cas++,n);
}
return ;
}
												

Biorhythms的更多相关文章

  1. poj1006 / hdu1370 Biorhythms (中国剩余定理)

    Biorhythms 题意:读入p,e,i,d 4个整数,已知(n+d)%23=p;   (n+d)%28=e;   (n+d)%33=i ,求n .        (题在文末) 知识点:中国剩余定理 ...

  2. poj 1006:Biorhythms(水题,经典题,中国剩余定理)

    Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 110991   Accepted: 34541 Des ...

  3. POJ 1006 - Biorhythms (中国剩余定理)

    B - Biorhythms Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Subm ...

  4. [POJ] #1006# Biorhythms : 最小公倍数/同余问题

    一. 题目 Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 127263   Accepted: 403 ...

  5. Poj 1006 / OpenJudge 2977 1006 Biorhythms/生理周期

    1.链接地址: http://poj.org/problem?id=1006 http://bailian.openjudge.cn/practice/2977 2.题目: Biorhythms Ti ...

  6. 算法练习之:Biorhythms

    Biorhythms Time Limit: 1000MS Memory Limit: 10000KB  Problem Description Some people believe that th ...

  7. Biorhythms(中国剩余定理)

    Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 127339   Accepted: 40342 Des ...

  8. POJ - 1006 Biorhythms 周期相遇 两个思路程序

    Description Some people believe that there are three cycles in a person's life that start the day he ...

  9. Biorhythms(poj1006+中国剩余定理)

    Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 117973   Accepted: 37026 Des ...

  10. Biorhythms(中国剩余定理)

    http://shuxueshi.jie.blog.163.com/blog/static/13611628820104179856631/ 这篇博客写的很棒! #include<stdio.h ...

随机推荐

  1. selfshadow

    realtime rendering v3 page 351 Moire pattern sruface acne artifacts ----------------------- 用 setsta ...

  2. Android - 标准VideoView播放演示样例

    标准VideoView播放演示样例 本文地址: http://blog.csdn.net/caroline_wendy 在Android SDK中的ApiDemos内, 提供标准播放视频的代码,使用V ...

  3. Nginx常用Rewrite(伪静态规则)WordPress/PHPCMS/ECSHOP/ShopEX/SaBlog/Discuz/DiscuzX/PHPWind/Typecho/DEDECMS

    目前已收集Wordpress.Wordpress二级目录.PHPCMS.ECSHOP.ShopEX.SaBlog.Discuz.Discuz X.PHPWind.Typecho.DEDECMS: Wo ...

  4. Linq 数据排序,分页

    在用Linq查询中,常常需要用到分页功能,因为每次都需要些分页这些功能,于是把分页功能提取出来,不喜大家勿喷,只是贴出来,自觉地很实用.一下贴出核心代码: /// <summary> // ...

  5. iOS_block代码块

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlX2VtaW5lbnQ=/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  6. uva507 - Jill Rides Again(最长连续和)

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=448">题目:uva507 - Jill ...

  7. python ——单下划线(约定)

    命名规则: 通常使用小写单词,必要时用下划线分隔增加可读性. 使用一个前导下划线仅用于不打算作为类的公共接口的内部方法和实例变量. Python不强制要求这样; 它取决于程序员是否遵守这个约定. 使用 ...

  8. 【Excle数据透视表】如何禁用数据透视表的总计行/列

    如上图:有行合计也有列合计.现在我们需要将行列合计都去除,如何操作呢? 解决办法一: 数据透视表区域任意单元格→数据透视表工具→设计→布局→总计→对行和列禁用 解决办法二: 数据透视表区域任意单元格→ ...

  9. 为什么 Linux 的 htop 命令完胜 top 命令

    在 Linux 系统中,top 命令用来显示系统中正在运行的进程的实时状态,它显示了一些非常有用的信息,比如 CPU 利用情况.内存消耗情况,以及每个进程情况等.但是,你知道吗?还有另外一个命令行工具 ...

  10. xcode几个常用的快捷键

    command + ctrl + e   修改变量的名称:选中某个变量,按下该快捷键,可以批量修改对应的变量名称 command + shift + j 定位到文档导航界面,然后通过上下方向键,可以快 ...