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. samba 服务实现在windows共享文件

    1. 什么是samba Samba服务类似于windows上的共享功能,可以实现在Linux上共享文件,windows上访问,当然在Linux上也可以访问到. 是一种在局域网上共享文件和打印机的一种通 ...

  2. malloc,free和new,delete之间的区别

    1.malloc free 是c语言里面的,不过在c++中也能使用,这个只是申请的一块内存,一般不能申请对象的内存空间:2.new delete,是c++的,申请的也是一块内存,只是这个可以申请对象. ...

  3. Hibernate分页功能数据重复问题

    今天遇到一个很憋屈的问题那就是hibernate分页查询中出现重复数据,本来一直没有在意,以为是数据问题,但是一查程序和数据都没有问题,继续深入查看,找到问题了就是order By 时出的问题,唉.. ...

  4. Hive 脚本执行

    hive执行脚本 hive -e “sql语句” 会将查询的结果打印在控制台上.  hive -e “sql语句” >> xxx 会将查询的结果重定向到xxx文件中,会显示OK和抓取的数据 ...

  5. CentOS6.4 安装 codeblocks-12.11

    FROM: http://blog.csdn.net/theegao/article/details/8750239 一.下载 1.   codeblocks-12.11-1.el6.x86_64.t ...

  6. ASP.NET MVC学习---(八)三个比较常用的方便的功能

    通过之前的了解 现在我们已经可以使用mvc进行一些简单的开发 但是还不够 哪里不够呢? 为什么现在的程序员喜欢用mvc进行开发 不就是因为它爽吗? 之前介绍的那些特点仅仅是mvc框架的一小部分 只是一 ...

  7. [Algorithms] Refactor a Linear Search into a Binary Search with JavaScript

    Binary search is an algorithm that accepts a sorted list and returns a search element from the list. ...

  8. 【转】WEB开发三层架构概述

    关于 三层架构(3-tier application) 通常意义上的三层架构就是将整个业务应用划分为:表现层(UI).业务逻辑层(BLL).数据访问层(DAL).区分层次的目的即为了“高内聚,低耦合” ...

  9. Java---24---基本数据类型对象包装类

    基本数据类型对象包装类 byte Byte short  short int  Integer boolean  Boolean float    Float double   Double char ...

  10. Git合并分支命令参数详解:git merge --ff

    今天研究了一下git merge命令常用参数,并分别用简单的例子实验了一下,整理如下: 输入命令git merge -h可以查看相关参数: --ff  快速合并,这个是默认的参数.如果合并过程出现冲突 ...