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 ...
随机推荐
- php配置opcache
官网地址:http://php.net/opcache 使用下列推荐设置来获得较好的 性能: opcache.memory_consumption=128 opcache.interned_strin ...
- 单向HASH——MurmurHash
//seed 是大质数unsigned long long MurmurHash64B ( const void * key, int len, unsigned int seed ) { const ...
- gIt 常用 操作
git提交代码流程git status -- 查看当前仓库状态git add -- 添加到临时仓库git commit -m '注释' -- 添加到临时仓库git status -- 查看当前仓库 ...
- YY大厅接受不到documentcompleted事件处理
多玩大厅在接受到了页面的documentcompleted事件,才会把遮在页面前面的YY游戏中去掉,我们的游戏页面,YY大厅接收不到事件,所以就排查了下 发现原因在于js脚本里有个用iframe做上报 ...
- Linux c编程:同步属性
就像线程具有属性一样,线程的同步对象(如互斥量.读写锁.条件变量.自旋锁和屏障)也有属性 1.互斥量属性 用pthread_mutexattr_init初始化pthread_mutexattr_t结构 ...
- centos7 Authentication failure
root@localhost ~]#su bash-4.2$ su Password: su: Authentication failure //这里切换的是系统用户,现在还不清楚为什么postgre ...
- https 请求发送 例子 tls && ssl
package com.dooioo.training.helper; import java.io.IOException; import java.io.UnsupportedEncodingEx ...
- 第7条:用列表推导式来取代map和filter
核心知识点: 1.列表推导式要比内置的map和filter函数清晰,因为它无需额外编写lambda表达式. 2.列表推导式可以跳过输入列表中的某些元素,如果改用map来做,那就必须辅以filter方能 ...
- NCL 小图对其问题
从昨天下午开始的折腾终于告一段落,虽然解决得不甚完善,只是图可以用了…… 问题起自想把之前手动拼成的一页四张的图用脚本自动生成,这样一方面应该对得更齐一点,另一方面大大节省人工. 这本来应该是件很容易 ...
- 常见http返回状态码
200:表示从客户端发来的请求在服务器端被正常处理了. 302:临时重定向,该状态码表示请求的资源已经被分配了新的URI,希望用户本次能够通过新的UIRI访问. 304:未修改,服务端资源未改变,可直 ...