Biorhythms(poj1006+中国剩余定理)
Biorhythms
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 117973 | Accepted: 37026 |
Description
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.
Source
题意:
生理周期
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 117973 | Accepted: 37026 |
Description
Input
当p = e = i = d = -1时,输入数据结束。
Output
采用以下格式:
Case 1: the next triple peak occurs in 1234 days.
注意:即使结果是1天,也使用复数形式“days”。
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.
Source
Translator
解法:中国剩余定理,看了很多的博客终于总结了自己的模板,也是我入门题了。
关于中国剩余定理的解释: http://www.cnblogs.com/yuyixingkong/p/4358300.html 与 http://baike.sogou.com/v1853008.htm 与 http://www.cnblogs.com/tom987690183/p/3260625.html 与 http://blog.csdn.net/u010468553/article/details/38346195 都可以作为参考的博客;
关于欧几里得和逆元的解释:http://blog.csdn.net/cqlf__/article/details/7953039 与 http://blog.csdn.net/acdreamers/article/details/8220787 都可以作为参考的博客;
转载请注明出处:寻找&星空の孩子
题目链接:poj1006
#include<stdio.h>
#define LL __int64
LL m[]={,,};
LL at[];
LL s;
void exgcd(LL a,LL b,LL &d,LL &x,LL &y)
{
if(b==)
{
x=;
y=;
d=a;
return ;
}
else
{
exgcd(b,a%b,d,y,x);
y-=x*(a/b);
}
}
LL China(int r)
{
LL Mc=;
LL i,Mi,x,y,d,as=;
for(i=; i<r; i++)
Mc*=m[i];
for(i=; i<r; i++)
{
Mi=Mc/m[i];
exgcd(Mi,m[i],d,x,y);
as=(as+Mi*x*at[i])%Mc;
}
as-=s;
if(as<=)
as+=Mc;
return as;
}
LL work()
{
if(!(at[]%m[]||at[]%m[]||at[]%m[]))
return **-s;
else
China();
}
int main()
{
int test=;
while(scanf("%I64d%I64d%I64d%I64d",&at[],&at[],&at[],&s)!=EOF)
{
if(at[]==-&&at[]==-&&at[]==-&&s==-) break;
printf("Case %d: the next triple peak occurs in %I64d days.\n",test++,work());
}
return ;
}
Biorhythms(poj1006+中国剩余定理)的更多相关文章
- POJ1006: 中国剩余定理的完美演绎
POJ1006: 中国剩余定理的完美演绎 问题描述 人自出生起就有体力,情感和智力三个生理周期,分别为23,28和33天.一个周期内有一天为峰值,在这一天,人在对应的方面(体力,情感或智力)表现最 ...
- POJ1006 - Biorhythms(中国剩余定理)
题目大意 略...有中文... 题解 就是解同余方程组 x≡(p-d)(mod 23) x≡(e-d)(mod 28) x≡(i-d)(mod 33) 最简单的中国剩余定理应用.... 代码: #in ...
- [转]POJ1006: 中国剩余定理的完美演绎
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 117973 Accepted: 37026 Des ...
- Biorhythms(中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 127339 Accepted: 40342 Des ...
- poj1006 中国剩余定理&&中国剩余定理解析
poj 1006 题的思路不是很难的,可以转化数学式: 现设 num 是下一个相同日子距离开始的天数 p,e,i,d 如题中所设! 那么就可以得到三个式子:( num + d ) % 23 == p: ...
- POJ 1006 Biorhythms (中国剩余定理)
在POJ上有译文(原文右上角),选择语言:简体中文 求解同余方程组:x=ai(mod mi) i=1~r, m1,m2,...,mr互质利用中国剩余定理令M=m1*m2*...*mr,Mi=M/mi因 ...
- POJ1006: 中国剩余定理的完美演绎(非原创)
问题描述 人自出生起就有体力,情感和智力三个生理周期,分别为23,28和33天.一个周期内有一天为峰值,在这一天,人在对应的方面(体力,情感或智力)表现最好.通常这三个周期的峰值不会是同一天.现在给出 ...
- poj 1006 Biorhythms (中国剩余定理模板)
http://poj.org/problem?id=1006 题目大意: 人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这 ...
- 【题解】UVA756 Biorhythms (中国剩余定理)
UVA756:https://www.luogu.org/problemnew/show/UVA756 思路 几乎是裸的中国剩余定理模板题 但是需要注意的是此题并不是求最小正整数解 而是求大于d的解 ...
随机推荐
- 零基础入门学习javase,应该怎么学?这是我给你的一个建议
我们知道Java有三个方向,JavaSE,JavaME,JavaEE(老程序员可能会叫J2EE等,不过SUN已经改名了).JavaME主要是嵌入式与游戏开发.那我们先看JavaSE,因为只有学好了Ja ...
- pytest进阶之配置文件
前言 pytest配置文件能够改变pytest框架代码的运行规则.比如修改pytest收集用例的规则,添加命令行参数等等!下面我们来一一讲解常用的一些配置项 Help 通过命令pytest --hel ...
- Mac PyCharm激活码(转载CSDN的猪哥66文章)
对于很多刚接触python的新手来说,各种资源都是非常稀缺的.我也是刚接触python不久的新手,有好的资源就分享出来大家共同进步. 这篇文章是教你怎么安装和破解pycharm的教程,我在2019.4 ...
- Java基础系列-ArrayList
原创文章,转载请标注出处:<Java基础系列-ArrayList> 一.概述 ArrayList底层使用的是数组.是List的可变数组实现,这里的可变是针对List而言,而不是底层数组. ...
- Spring Cloud Alibaba基础教程:Nacos的集群部署
继续说说生产环境的Nacos搭建,通过上一篇<Spring Cloud Alibaba基础教程:Nacos的数据持久化>的介绍,我们已经知道Nacos对配置信息的存储原理,在集群搭建的时候 ...
- DevExpress控件安装破解和汉化使用教程
这段时间因公司业务需要.net开发且需要用到DevExpress控件,我自己研究学习了一下,用的是visual studio(2013)和DevExpress(V14.1.4),VS2013的下载安装 ...
- 前端笔记之HTML
前端三层:内容层(结构层)HTML.样式层(表现层)CSS.行为层JavaScript 层 语言 含义 结构层 HTML 由 HTML 或 XHTML之类的标记语言负责创建.标签,也就是那些出现在尖括 ...
- Asp.NetCore轻松学-配置服务 apollo 部署实践
前言 Apollo(阿波罗)是携程框架部门研发的分布式配置中心,能够集中化管理应用不同环境.不同集群的配置,配置修改后能够实时推送到应用端,并且具备规范的权限.流程治理等特性,适用于微服务配置 ...
- 【原】无脑操作:IDEA + maven + Shiro + SpringBoot + JPA + Thymeleaf实现基础认证权限
开发环境搭建参见<[原]无脑操作:IDEA + maven + SpringBoot + JPA + Thymeleaf实现CRUD及分页> 需求: ① 除了登录页面,在地址栏直接访问其他 ...
- 排错:Windows系统异常导致Filebeat无法正常运行
Windows 下Filebeat排错Case实例一份,请查收. 问题描述: Windows Server下Filebeat Agent服务无法正常启动,导致网络数据打点无法正常进行,影响大范围用户网 ...