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. util.select.js

    ylbtech-JavaScript-util: util.select.js 筛选工具 1.A,JS-效果图返回顶部   1.B,JS-Source Code(源代码)返回顶部 1.B.1, m.y ...

  2. 从头认识Spring-1.7 如何通过属性注入Bean?(1)-如何通过属性向对象注入值?

    这一章节我们来讨论一下如何通过属性注入Bean? 这一章节分为两部分,第一部分我们通过属性向对象注入值,第二部分我们通过属性向对象注入还有一个对象的引用. 1.如何通过属性向对象注入值? (1)dom ...

  3. left menu

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. C5:单例模式 Singleton

    保证一个类仅有一个实例,并提供一个访问它的全局访问点. 应用场景:A.一个无状态的类使用单例,可以节省内存B.全局或配置类(其实这个也是无状态的)C.脚本或程序从运行开始到结束,仅需要一个实例来保证数 ...

  5. 最简单的基于FFmpeg的移动端样例附件:Android 自带播放器

    ===================================================== 最简单的基于FFmpeg的移动端样例系列文章列表: 最简单的基于FFmpeg的移动端样例:A ...

  6. Android下Slidingmenu和actionbarsherlock的使用

    1 http://blog.csdn.net/wangjinyu501/article/details/9331749  博客很多,推荐此教程,slidingmenu的demo可以演示 2 http: ...

  7. centos源码安装lnmp

    参考博客:http://blog.csdn.net/yanzi1225627/article/details/49123659 服务器环境为:CentOS6.6 64位(虚拟机) 一.安装前准备 创建 ...

  8. CSS 选择器 :last-child与:last-of-type的区别

    :last-child----represents the last element among a group of sibling elements. CSS伪类 :last-child 代表在一 ...

  9. es快照和备份

    注册前要注意配置文件加上 path.repo: ["/data/es_backup"] 然后重启es 不然会报错doesn't match any of the locations ...

  10. go学习资料

    go书单 1.代码规范 https://github.com/golang/go/wiki/CodeReviewComments 2.基础知识 先看: https://github.com/mikel ...