Biorhythms

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

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

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.

 
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
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.
 
Source
思路:暴力就直接暴力到21252就好了;
     中国剩余定理,因为大多数中国剩余不可能两两互质,所以用了自己写的一代码
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 999999999
//#pragma comment(linker, "/STACK:102400000,102400000")
int scan()
{
int res = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
return res ;
}
int a[];
int b[];
int gcd(int x,int y)
{
if(x%y==)
return y;
else
return gcd(y,x%y);
}
void exgcd(int a, int b, int &x, int &y)
{
if(b == )
{
x = ;
y = ;
return;
}
exgcd(b, a % b, x, y);
int tmp = x;
x = y;
y = tmp - (a / b) * y;
}
int check()
{
for(int i=;i<;i++)
if(a[i]!=-)
return ;
return ;
}
int main()
{
int x,y,z,i,t;
scanf("%d",&x);
while(x--)
{
int flag=;
while()
{
z=;
b[]=;
b[]=;
b[]=;
for(i=;i<z;i++)
scanf("%d",&a[i]);
if(!check())
break;
int a1=a[],b1=b[];
//int jie=1;
for(i=;i<z-;i++)
{
int a2=a[i],b2=b[i];
int xx,yy;
int gys=gcd(b1,b2);
/*if((a2-a1)%gys)
{
jie=0;
break;
}*/
exgcd(b1,b2,xx,yy);
xx=(xx*(a2-a1))/gys;
int gbs=b1*b2/gys;
a1=(((xx*b1+a1)%gbs)+gbs)%gbs;
b1=gbs;
}
a1-=a[];
if(a1<=)
a1+=b1; printf("Case %d: the next triple peak occurs in %d days.\n",flag++,a1);
}
}
return ;
}

hdu 1370 || poj 1006 简单的中国剩余定理或者暴力的更多相关文章

  1. POJ 1006 生理周期(中国剩余定理)

    POJ 1006 生理周期 分析:中国剩余定理(注意结果要大于d即可) 代码: #include<iostream> #include<cstdio> using namesp ...

  2. poj 1006 Biorhythms (中国剩余定理模板)

    http://poj.org/problem?id=1006 题目大意: 人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这 ...

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

    在POJ上有译文(原文右上角),选择语言:简体中文 求解同余方程组:x=ai(mod mi) i=1~r, m1,m2,...,mr互质利用中国剩余定理令M=m1*m2*...*mr,Mi=M/mi因 ...

  4. POJ 1006 Biorhythnms(中国剩余定理)

    http://poj.org/problem?id=1006 题意: (n+d) % 23 = p ;(n+d) % 28 = e ;(n+d) % 33 = i ; 求最小的n. 思路: 这道题就是 ...

  5. hdu 1573 X问题【扩展中国剩余定理】

    扩展中国剩余定理的板子,合并完之后算一下范围内能取几个值即可(记得去掉0) #include<iostream> #include<cstdio> #include<cm ...

  6. HDU 6463.超级无敌简单题-卡边界的暴力 (“字节跳动-文远知行杯”广东工业大学第十四届程序设计竞赛)

    超级无敌简单题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  7. HDU 3268/POJ 3835 Columbus’s bargain(最短路径+暴力枚举)(2009 Asia Ningbo Regional)

    Description On the evening of 3 August 1492, Christopher Columbus departed from Palos de la Frontera ...

  8. poj 2891 Strange Way to Express Integers(中国剩余定理)

    http://poj.org/problem?id=2891 题意:求解一个数x使得 x%8 = 7,x%11 = 9; 若x存在,输出最小整数解.否则输出-1: ps: 思路:这不是简单的中国剩余定 ...

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

    题目大意 略...有中文... 题解 就是解同余方程组 x≡(p-d)(mod 23) x≡(e-d)(mod 28) x≡(i-d)(mod 33) 最简单的中国剩余定理应用.... 代码: #in ...

随机推荐

  1. 实体框架 Code First

    原文:https://msdn.microsoft.com/zh-cn/en-zn/data/jj591621

  2. React组件,React和生命周期

    笔记,具体可以看看这个博客: https://segmentfault.com/a/1190000004168886?utm_source=tag-newest react 的jsx document ...

  3. 解读jquery.filtertable.min

    jQuery.FilterTable是一款表格搜索过滤和单元格高亮插件. 该插件允许你对任意表格进行条件过滤,并且它会将搜索到的结果单元格高亮显示,非常实用和强大. 使用方法在页面中引入jquery和 ...

  4. MFC六大核心机制之五、六:消息映射和命令传递

    作为C++程序员,我们总是希望自己程序的所有代码都是自己写出来的,如果使用了其他的一些库,也总是千方百计想弄清楚其中的类和函数的原理,否则就会感觉不踏实.所以,我们对于在进行MFC视窗程序设计时经常要 ...

  5. zw版【转发·台湾nvp系列Delphi例程】HALCON Regiongrowing

    zw版[转发·台湾nvp系列Delphi例程]HALCON Regiongrowing procedure TForm1.Button1Click(Sender: TObject);var img : ...

  6. Python: 去掉字符串开头、结尾或者中间不想要的字符

    ①Strip()方法用于删除开始或结尾的字符.lstrip()|rstirp()分别从左右执行删除操作.默认情况下会删除空白或者换行符,也可以指定其他字符. ②如果想处理中间的空格,需要求助其他技术 ...

  7. linux常用命令:find命令之xargs

    在使用 find命令的-exec选项处理匹配到的文件时, find命令将所有匹配到的文件一起传递给exec执行.但有些系统对能够传递给exec的命令长度有限制,这样在find命令运行几分钟之后,就会出 ...

  8. 神州行省内流量套餐6元500M申请,发送BLSN6到10086即可

    神州行流量套餐,神州行省内流量套餐6元500M申请,发送BLSN6到10086即可申请开通专属流量包,比全国5元30M划算多了4G全国流量套餐 5元/30M 10元/100M 20元/300M 30元 ...

  9. 微服务:Java EE的拯救者还是掘墓人?

    有人认为,微服务的大行其道是在给Java EE下达死刑判决书.也有人认为,Java EE已死的论调可笑至极.读者朋友,你们怎么看? 引言 有人说,Java确实过于臃肿,经常“小题大做”.但PHP.No ...

  10. centos+Jenkins+maven搭建持续集成

    Jenkins是一个开源软件项目,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能 什么是持续集成 随着软件开发复杂度的不断提高,团队开发成员间如何更好地协同工作以确保软件开发的质量已经慢慢成 ...