HDU1370Biorhythms(中国剩余定理||暴力)
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(中国剩余定理||暴力)的更多相关文章
- uva11754 中国剩余定理+暴力搜索
是当y的组合数较小时,暴力枚举所有组合,然后用中国剩余定理求每种组合的解,对解进行排序即可 注意初始解可能是负数,所以如果凑不够S个,就对所有解加上M,2M.... 当y的组合数较大时,选择一个k/x ...
- UVA 11754 Code Feat 中国剩余定理+暴力
lrj白书例题,真好 #include <stdio.h> #include <iostream> #include <vector> #include <m ...
- UVA 11754 (暴力+中国剩余定理)
题目链接: http://www.bnuoj.com/v3/problem_show.php?pid=20172 题目大意:有C个模方程,每个方程可能有k余数,求最小的S个解. 解题思路: 看见模方程 ...
- poj1006 ( hdu1370 ):中国剩余定理裸题
裸题,没什么好说的 第一个中国剩余定理 写暴力都过了..可见这题有多水 代码: #include<iostream> #include<stdio.h> #include< ...
- [bzoj2142]礼物(扩展lucas定理+中国剩余定理)
题意:n件礼物,送给m个人,每人的礼物数确定,求方案数. 解题关键:由于模数不是质数,所以由唯一分解定理, $\bmod = p_1^{{k_1}}p_2^{{k_2}}......p_s^{{k_ ...
- [SDOI2010] 古代猪文 (快速幂+中国剩余定理+欧拉定理+卢卡斯定理) 解题报告
题目链接:https://www.luogu.org/problemnew/show/P2480 题目背景 “在那山的那边海的那边有一群小肥猪.他们活泼又聪明,他们调皮又灵敏.他们自由自在生活在那绿色 ...
- 清北学堂-DAY2-数论专题-中国剩余定理(CRT)
首先请看定义:(百科上抄下来的)孙子定理是中国古代求解一次同余式组(见同余)的方法.是数论中一个重要定理.又称中国余数定理. 一元线性同余方程组问题最早可见于中国南北朝时期(公元5世纪)的数学著作&l ...
- Java-POJ1006-Biorhythms(中国剩余定理)
https://blog.csdn.net/shanshanpt/article/details/8724769 有中文题面,就不解释了. 妥妥的中国剩余定理没跑了. Java跑得慢,一点办法也没有, ...
- E - Two Arithmetic Progressions(CodeForces - 710D)(拓展中国剩余定理)
You are given two arithmetic progressions: a1k + b1 and a2l + b2. Find the number of integers x such ...
随机推荐
- 解决QT:forward declaration of 'struct Ui::xxx';invalid use of incomplete struct "Ui::Widget" 等莫名奇异错误
今天在进行QT Widget的UI设计时,改了下Widget的对象名,然后在多次成功编译执行后,执行清理,又一次构建,就出现了好多莫名奇异的错误: widget.h:12: 错误:forward de ...
- springMVC的注释集合
SpringMVC的工作原理 主要核心实现是DispatcherServlet. 一般来讲客户端对服务器发送请求,是由DispatcherServlet控制的,DispatcherServlet接受到 ...
- 3354 [IOI2005]河流
题目描述 几乎整个Byteland王国都被森林和河流所覆盖.小点的河汇聚到一起,形成了稍大点的河.就这样,所有的河水都汇聚并流进了一条大河,最后这条大河流进了大海.这条大河的入海口处有一个村庄——名叫 ...
- 【BZOJ3105】[cqoi2013]新Nim游戏 贪心+线性基
[BZOJ3105][cqoi2013]新Nim游戏 Description 传统的Nim游戏是这样的:有一些火柴堆,每堆都有若干根火柴(不同堆的火柴数量可以不同).两个游戏者轮流操作,每次可以选一个 ...
- zipkin环境搭建
基于jdk1.8 下载zipkin jar包 用wget下载zipkin官方最新jar包 wget -O zipkin.jar 'https://search.maven.org/remote_con ...
- Netty实现java多线程Post请求解析(Map参数类型)—SKY
netty解析Post的键值对 解析时必须加上一个方法,ch.pipeline().addLast(new HttpObjectAggregator(2048)); 放在自己的Handel前面. ht ...
- 九度OJ 1189:还是约瑟夫环 (约瑟夫环)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:820 解决:522 题目描述: 生成一个长度为21的数组,依次存入1到21: 建立一个长度为21的单向链表,将上述数组中的数字依次存入链表每 ...
- spring 配置c3p0连接池
一.导入与c3p0相关的jar包 二.xml配置文件 CombopooledDataSource类中提供了相应属性的set方法,因此可是使用属性注入的方式实例化对象. 三.示例 在userServic ...
- ubuntu 13.04 设定静态IP
切换到root用户,然后进入/etc/network目录.备份interfaces文件(备份文件是一个好习惯) 下面编辑interfaces文件,添加如下语句: # Assgin static IP ...
- bd存储
var sessionData = new Array();var setSessionData=function(key,val){ if(sessionStorage){ sessionStora ...