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的解 ...
随机推荐
- 浏览器加载 CommonJS 模块的原理与实现
就在这个周末,npm 超过了 cpan ,成为地球上最大的软件模块仓库. npm 的模块都是 JavaScript 语言写的,但浏览器用不了,因为不支持 CommonJS 格式.要想让浏览器用上这些模 ...
- 100 天从 Python 新手到大师
Python应用领域和就业形势分析 简单的说,Python是一个“优雅”.“明确”.“简单”的编程语言. 学习曲线低,非专业人士也能上手 开源系统,拥有强大的生态圈 解释型语言,完美的平台可移植性 支 ...
- Akka实践一些总结
最近在一些服务中使用了akka,主要用来做异步解耦和本地消息分发(路由),这里简单总结一下用法. 与spring集成 网上有不少集成的例子,要使用到spring的扩展. 我这边没有这样处理,而是简单把 ...
- Visio打开或取消箭头的自动吸附和自动连接
在用Visio画图时Visio的自动对齐.自动连接.自动吸附功能确实能带了很多便利.但在画连接线时,Visio总是自动连接箭头与图形的固定节点,想要微调一下连接位置,就显得很不方便,需要关闭自动连接功 ...
- Git协同工作流介绍
git相关的文章和教程非常多,但是系统介绍和了解工作流的人并不多,在使用过程中用错或用偏的也不少,这里分享的是,假设你已经入门的情况下,我们如何去选择适合团队需要的工作流. git优势 这里先唠叨gi ...
- C#开发APP,ToolBar控件在Smobiler中的使用方式【附案例源码】——Smobiler移动开发平台
控件说明 底部工具栏控件. 效果演示 其他效果 该界面为仿淘宝UI制作的一个简单的UI模板,源码获取方式请拉至文章末尾. 特色属性 属性 属性说明 Direction(相对布局) 容器主轴方向. Fl ...
- vue3+typescript引入外部文件
vue3+typescript中引入外部文件有几种方法 (eg:引入echarts) 第一种方法: 1 indext.html中用script引入 <div id="app" ...
- vue 设计一个倒计时秒杀的组件
简介: 倒计时秒杀组件在电商网站中层出不穷 不过思路万变不离其踪,我自己根据其他资料设计了一个vue版的 核心思路:1.时间不能是本地客户端的时间 必须是服务器的时间这里用一个settimeout ...
- Android之RxJava详解
文章大纲 一.什么是RxJava二.为什么要用RxJava三.RxJava使用详解四.项目源码下载五.参考文章 一.什么是RxJava Rx(Reactive Extensions)是一个库,用来 ...
- 第一周Python学习笔记
Python 基本语法: ① Python程序的格式:1.用代码高亮来标识函数丶语句等等 本身的代码高亮并没有实际的意义,只是用来辅助编程人员和阅读人员 更好的识别 2.程序以缩进来标识语句,缩进用 ...