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.

This problem contains multiple test cases!

The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.

The output format consists of N output blocks. There is a blank line between output blocks.

InputYou 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. 
OutputFor 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

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

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.

题意:

有3个循环周期,周期天数分别为23、28、33。对于某一年,已知某年这3个周期的某一峰值分别是当年的第a、b、c天,

问从第d天开始到最近一个满足3个周期都达到峰值的日期还有多少天。

简单的中国剩余定理。(kuangbin的模板)

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cstring>
int m[],Mod[],M;
long long extend_gcd(long long a,long long b,long long &x,long long &y)
{
if(a==&&b==) return -; if(b==){x=;y=;return a;}
long long d=extend_gcd(b,a%b,y,x); y-=a/b*x; return d;
}
long long mod_reverse(long long a,long long n)
{
long long x,y; long long d=extend_gcd(a,n,x,y);
if(d==) return (x%n+n)%n; else return -;
}
int T,a,b,c,d,Case;
void China()
{
long long res=;
m[]=a%Mod[];m[]=b%Mod[];m[]=c%Mod[];
for(int i=;i<=;i++){
res=res+M/Mod[i]*mod_reverse(M/Mod[i],Mod[i])*m[i]%M;
} res%=M;
res=res-d; if(res<=) res+=M;
printf("Case %d: the next triple peak occurs in %lld days.\n",++Case,res);
}
int main()
{
Mod[]=;Mod[]=;Mod[]=;M=**;
scanf("%d",&T);Case=;
while(~scanf("%d%d%d%d",&a,&b,&c,&d)) {
if(a==-&&b==-&&c==-) break;China();
}
return ;
}

HDU1370Biorhythms(中国剩余定理||暴力)的更多相关文章

  1. uva11754 中国剩余定理+暴力搜索

    是当y的组合数较小时,暴力枚举所有组合,然后用中国剩余定理求每种组合的解,对解进行排序即可 注意初始解可能是负数,所以如果凑不够S个,就对所有解加上M,2M.... 当y的组合数较大时,选择一个k/x ...

  2. UVA 11754 Code Feat 中国剩余定理+暴力

    lrj白书例题,真好 #include <stdio.h> #include <iostream> #include <vector> #include <m ...

  3. UVA 11754 (暴力+中国剩余定理)

    题目链接: http://www.bnuoj.com/v3/problem_show.php?pid=20172 题目大意:有C个模方程,每个方程可能有k余数,求最小的S个解. 解题思路: 看见模方程 ...

  4. poj1006 ( hdu1370 ):中国剩余定理裸题

    裸题,没什么好说的 第一个中国剩余定理 写暴力都过了..可见这题有多水 代码: #include<iostream> #include<stdio.h> #include< ...

  5. [bzoj2142]礼物(扩展lucas定理+中国剩余定理)

    题意:n件礼物,送给m个人,每人的礼物数确定,求方案数. 解题关键:由于模数不是质数,所以由唯一分解定理, $\bmod  = p_1^{{k_1}}p_2^{{k_2}}......p_s^{{k_ ...

  6. [SDOI2010] 古代猪文 (快速幂+中国剩余定理+欧拉定理+卢卡斯定理) 解题报告

    题目链接:https://www.luogu.org/problemnew/show/P2480 题目背景 “在那山的那边海的那边有一群小肥猪.他们活泼又聪明,他们调皮又灵敏.他们自由自在生活在那绿色 ...

  7. 清北学堂-DAY2-数论专题-中国剩余定理(CRT)

    首先请看定义:(百科上抄下来的)孙子定理是中国古代求解一次同余式组(见同余)的方法.是数论中一个重要定理.又称中国余数定理. 一元线性同余方程组问题最早可见于中国南北朝时期(公元5世纪)的数学著作&l ...

  8. Java-POJ1006-Biorhythms(中国剩余定理)

    https://blog.csdn.net/shanshanpt/article/details/8724769 有中文题面,就不解释了. 妥妥的中国剩余定理没跑了. Java跑得慢,一点办法也没有, ...

  9. E - Two Arithmetic Progressions(CodeForces - 710D)(拓展中国剩余定理)

    You are given two arithmetic progressions: a1k + b1 and a2l + b2. Find the number of integers x such ...

随机推荐

  1. 【v2.x OGE教程 11】 动画编辑器帮助文档

    ] 动画编辑器帮助文档 版本号 日期 作者 说明 1.0 2014-9-3 橙子游戏 文档创建       一.简单介绍 动画编辑器用于游戏动画的可视化编辑,支持序列帧动画和关键帧动画.通过解析生成的 ...

  2. PHP邮箱的正则表达式

    邮箱的正则:/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i

  3. Discrete Function(简单数学题)

    Discrete Function There is a discrete function. It is specified for integer arguments from 1 to N (2 ...

  4. JS表单提交

    测试一: function submit(){var form1=document.getElementById("form1")form1.action="/manag ...

  5. bash: /home/aprilpeng/.bashrc: Permission denied

    bash: /home/aprilpeng/.bashrc: Permission denied 出现这样的权限问题,一般是在切换用户的时候,用户没有该目录的权限 可以$chown -R git:us ...

  6. c++得到本地username和IP

    bool CDlgResetAlarmInfo::GetLocalUserNameAddIP(CString &a_lstrUserName ,CString &a_IpStr) { ...

  7. Struts2之ModelDriven的使用

    http://www.cnblogs.com/luoyanli/archive/2012/11/20/2778361.html 我们可以根据Action属性的不同将它分为两类:Field-Driven ...

  8. shell基础part3

    shell基础 一.环境变量配置文件简介 1.source命令的作用就是将环境变量配置文件强制生效,其格式为: source 环境变量配置文件或者 . 环境变量配置文件 2.环境变量配置文件中主要是定 ...

  9. 【转】.net中快捷键的使用

    当前行行首:Home 当前行行尾:End 当前文档首行:ctrl+Home 当前文档尾行:ctrl+End 选中当前行: ① 按Home(定位到行首)然后按Shift+Dnd(行尾)   {从行首连选 ...

  10. ios多种语言的本地化思路

    多语言在应用程序中一般有两种做法: 一.程序中提供给用户自己选择的机会: 二.根据当前用户当前移动设备的语言自动将我们的app切换对应语言. 第一种做法比较简单完全靠自己的发挥了,这里主要讲第二种做法 ...