Day7 - K - Biorhythms POJ - 1006
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
Output
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. 思路:同余方程组,此题三个模数互质,直接套即可,注意答案MOD一下21252(题意)
typedef long long LL;
typedef pair<LL, LL> PLL; void ex_gcd(LL a, LL b, LL &x, LL &y, LL &d) {
if(!b) {
d = a, x = , y = ;
} else {
ex_gcd(b, a%b, y, x, d);
y -= x*(a/b);
}
} LL inv(LL a, LL p) { // inv(a) (modp)
LL d, x, y;
ex_gcd(a, p, x, y, d);
return d == ?(x % p + p) % p : -;
} LL China(int *a, int *m, int n) { // x = a[i] (modm[i])
LL M = , ret = ;
for(int i = ; i < n; ++i) M *= m[i];
for(int i = ; i < n; ++i) {
LL w = M / m[i];
ret = (ret + w * inv(w, m[i]) * a[i]) % M;
}
return (ret + M) % M;
} int main() {
int kase = , d, a[], m[], MOD = ;
m[] = , m[] = , m[] = ;
while(scanf("%d%d%d%d", &a[], &a[], &a[], &d)) {
if(a[] == - && a[] == - && a[] == - && d == -) break;
LL ans = ((China(a, m, ) - d) % MOD + MOD) % MOD;
printf("Case %d: the next triple peak occurs in %lld days.\n", ++kase, ans?ans:MOD);
}
return ;
}
Day7 - K - Biorhythms POJ - 1006的更多相关文章
- Biorhythms POJ - 1006 中国剩余定理
定理证明:https://blog.csdn.net/d_x_d/article/details/48466957 https://blog.csdn.net/lyy289065406/article ...
- POJ 1006 - Biorhythms (中国剩余定理)
B - Biorhythms Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Subm ...
- POJ 1006 Biorhythms(中国剩余定理)
题目地址:POJ 1006 学习了下中国剩余定理.參考的该博客.博客戳这里. 中国剩余定理的求解方法: 假如说x%c1=m1,x%c2=m2,x%c3=m3.那么能够设三个数R1,R2,R3.R1为c ...
- POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理)
POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理) 题意分析 不妨设日期为x,根据题意可以列出日期上的方程: 化简可得: 根据中国剩余定理求解即可. 代码总览 #include & ...
- POJ 1006 生理周期(中国剩余定理)
POJ 1006 生理周期 分析:中国剩余定理(注意结果要大于d即可) 代码: #include<iostream> #include<cstdio> using namesp ...
- Poj 1006 / OpenJudge 2977 1006 Biorhythms/生理周期
1.链接地址: http://poj.org/problem?id=1006 http://bailian.openjudge.cn/practice/2977 2.题目: Biorhythms Ti ...
- 【中国剩余定理】POJ 1006 & HDU 1370 Biorhythms
题目链接: http://poj.org/problem?id=1006 http://acm.hdu.edu.cn/showproblem.php?pid=1370 题目大意: (X+d)%23=a ...
- poj 1006 Biorhythms (中国剩余定理模板)
http://poj.org/problem?id=1006 题目大意: 人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这 ...
- POJ 1006 Biorhythms --中国剩余定理(互质的)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 103539 Accepted: 32012 Des ...
随机推荐
- robot framework 如何自己写模块下的方法或者库
一.写模块(RF能识别的模块) 例如:F:\Python3.4\Lib\site-packages\robot\libraries这个库(包)下面的模块(.py),我们可以看下源码 注意:这种是以方法 ...
- js 原生url编码
参考:http://www.runoob.com/jsref/jsref-decodeuricomponent.html
- DAC
DAC的功能:可以输出电压(无触发,设置DAC转换值,DAC使能更新寄存器和启动转换)或者波形(连续转换,用DMA发送数据,定时器触发).首先有个正弦波波形的数组,内存到DAC的DMA通道不断的将正弦 ...
- java.lang.ClassCastException: android.app.Application cannot be cast to
出这个异常的原因是在项目中添加了新lication类(public class Application extends lication)之后,没有在AndroidManifest.xml中添加该类的 ...
- Dubbo 18 问
dubbo是什么 dubbo是一个分布式框架,远程服务调用的分布式框架,其核心部分包含: 集群容错:提供基于接口方法的透明远程过程调用,包括多协议支持,以及软负载均衡,失败容错,地址路由,动态配置等集 ...
- SpringSecurity-权限关联与控制
6.3 服务器端方法级权限控制 在服务器端我们可以通过Spring security提供的注解对方法来进行权限控制.Spring Security在方法的权限控制上 支持三种类型的注解,JSR-250 ...
- 阿里云服务器Ubantu16.04升级python3.6
从ppa上下载下载python3.6 sudo apt-get install software-properties-common#使用 “add-apt-repository” 脚本添加 ppa ...
- mkvirtualenv: 未找到命令的解决方法
1.升级python包管理工具pip pip install --upgrade pip 备注:当你想升级一个包的时候 `pip install --upgrade 包名` 2.python虚拟环境安 ...
- [python]ubuntu下的python2和python3
在终端分别输入python,python2,python3python和python2默认都是python2python3才是python3 Ubuntu下是默认没有pip的,需要自己手动安装 sud ...
- unity渲染优化
https://blog.csdn.net/yudianxia/article/details/79339103 https://blog.csdn.net/e295166319/article/de ...