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的解 ...
随机推荐
- asp.net core系列 60 Ocelot 构建服务认证示例
一.概述 在Ocelot中,为了保护下游api资源,用户访问时需要进行认证鉴权,这需要在Ocelot 网关中添加认证服务.添加认证后,ReRoutes路由会进行身份验证,并使用Ocelot的基于声明的 ...
- DevOps实践之一:基于Docker构建企业Jenkins CI平台
基于Docker构建企业Jenkins CI平台 一.什么是CI 持续集成(Continuous integration)是一种软件开发实践,每次集成都通过自动化的构建(包括编译,发布,自动化测试)来 ...
- Java集合 - List介绍及源码解析
(源码版本为 JDK 8) 集合类在java.util包中,类型大体可以分为3种:Set.List.Map. JAVA 集合关系(简图) (图片来源网络) List集合和Set集合都是继承Collec ...
- 45个值得收藏的 CSS 形状
摘要: CSS炫技. 原文:45个值得收藏的 CSS 形状 作者:前端小智 Fundebug经授权转载,版权归原作者所有. CSS能够生成各种形状.正方形和矩形很容易,因为它们是 web 的自然形状. ...
- 什么是CSS
CSS是Cascading Style Sheet的缩写.译作”层叠样式表单“.是用于(增强)控制网页样式并允许将样式信息与网页内容分离的一种标记性语言.使用CSS样式可以控制许多仅使用HTML无法控 ...
- Android之Retrofit详解(转载)
说明:该文章转载于https://www.jianshu.com/p/a3e162261ab6 前言 在Andrroid开发中,网络请求十分常用 而在Android网络请求库中,Retrofit是当下 ...
- SQL Server关于predicate、density、selectivity、cardinality名词浅析
在SQL Server中,我们要看懂执行计划和统计信息,我们可能需要深刻理解一些关键词,例如密度(Density).选择性(Selectivity).谓词(predicate).基数(Cardin ...
- SQLServer之删除用户自定义数据库用户
删除用户自定义数据库用户注意事项 不能从数据库中删除拥有安全对象的用户. 必须先删除或转移安全对象的所有权,才能删除拥有这些安全对象的数据库用户. 不能删除 guest 用户,但可在除 master ...
- NumPy的基本用法
NumPy简介:NumPy是高性能科学计算和数据分析的基础包.是pandas等其他各种工具的基础NumPy主要功能:ndarray,一个多维数组结构,高效且节省空间无需循环对数组数据进行快速运算的数学 ...
- 微信小程序客服消息开发实战:实时在手机上接收小程序客服消息通知,以及在手机上回复
在微信小程序开发中,可以非常方便的集成客服功能,只需要一行代码便可以将用户引导至客服会话界面.这行代码就是: <button open-type="contact" bind ...