Biorhythms(中国剩余定理(模板题))
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.
#include<cstdio>
#include<cstring>
#include<stack>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>
#include<vector>
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
int m,n,p,k;
int str[];
int visit[][];
int dis[];
int di[][]={{-,},{,},{,-},{,}};
map<ll,ll>::iterator it;
void exgcd(int a,int b,int &x,int &y)
{
if(b==)
{
x=;
y=;
return ;
}
int x1,y1;
exgcd(b,a%b,x1,y1);
x=y1;
y=x1-a/b*y1;
}
int chinese_pp(int str[],int dis[],int l)
{
int res=,n=,x,y;
for(int i=;i<l;i++)
{
n*=str[i];
}
for(int i=;i<l;i++)
{
int t=n/str[i];
exgcd(t,str[i],x,y);
res=(res+dis[i]*x*t)%n;
}
return (res%n+n)%n;
}
int main()
{
int flag=;
while(cin>>m>>n>>p>>k)
{
flag++;
if(m==-&&n==-&&p==-&&k==-)
break;
str[]=;dis[]=m;
str[]=;dis[]=n;
str[]=;dis[]=p;
int ans=chinese_pp(str,dis,)-k;
if(ans<=)
{
ans+=;
}
printf("Case %d: the next triple peak occurs in %d days.\n",flag,ans);
}
}
Biorhythms(中国剩余定理(模板题))的更多相关文章
- Biorhythms(中国剩余定理)
http://shuxueshi.jie.blog.163.com/blog/static/13611628820104179856631/ 这篇博客写的很棒! #include<stdio.h ...
- poj 1006 Biorhythms (中国剩余定理模板)
http://poj.org/problem?id=1006 题目大意: 人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这 ...
- POJ 1006 - Biorhythms (中国剩余定理)
B - Biorhythms Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Subm ...
- 中国剩余定理模板 51nod 1079
题目链接:传送门 推荐博客:https://www.cnblogs.com/freinds/p/6388992.html (证明很好,代码有误). 1079 中国剩余定理 基准时间限制:1 秒 空间 ...
- Monkey Tradition---LightOj1319(中国剩余定理模板)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1319 题意:有 n 个猴子,n 棵树,树的高度为 L ,每个猴子刚开始的时候都在树的底 ...
- POJ 1006 Biorhythms --中国剩余定理(互质的)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 103539 Accepted: 32012 Des ...
- poj1006 ( hdu1370 ):中国剩余定理裸题
裸题,没什么好说的 第一个中国剩余定理 写暴力都过了..可见这题有多水 代码: #include<iostream> #include<stdio.h> #include< ...
- poj 1006中国剩余定理模板
中国剩余定理(CRT)的表述如下 设正整数两两互素,则同余方程组 有整数解.并且在模下的解是唯一的,解为 其中,而为模的逆元. 模板: int crt(int a[],int m[],int n) { ...
- [洛谷P1495] 曹冲养猪 (中国剩余定理模板)
中国剩余定理(朴素的)用来解线性同余方程组: x≡a[1] (mod m[1]) x≡a[2] (mod m[2]) ...... x≡a[n] (mod m[n]) 定义ms=m[1]*m[2]*. ...
- POJ 1006 Biorhythms(中国剩余定理)
题目地址:POJ 1006 学习了下中国剩余定理.參考的该博客.博客戳这里. 中国剩余定理的求解方法: 假如说x%c1=m1,x%c2=m2,x%c3=m3.那么能够设三个数R1,R2,R3.R1为c ...
随机推荐
- vue如何循环同一个echarts图表
因为我们知道echarts图表需要一个ID节点,所以我们循环echarts同一个图表时要考虑ID节点变化问题.废话不多说,直接上demo效果. 这里有一位分析师在不同的模拟组合,这时需求要在dialo ...
- 数据库设计系列之四--ER图
逻辑设计是做什么? 1.将需求转化为数据库的逻辑模型 2.通过ER图的型式对逻辑模型进行展示 3.同所选用的具体的DBMS系统无关
- 【python】numpy pandas 特性(随时更新)
[value map] 用df.replace(dict)可以解决.但是如果dict太大,会非常非常慢. [array相加的维度规律][广播] (2,3) 能和 (3,) 相加,不能和(2,)相加 ( ...
- tf随笔-6
import tensorflow as tfx=tf.constant([-0.2,0.5,43.98,-23.1,26.58])y=tf.clip_by_value(x,1e-10,1.0)ses ...
- WampServer常用环境配置
WampServer即Windows Apache Mysql PHP集成安装环境,就是在window下的apache.php和mysql的服务器软件. 其特点就是 1.支持中文语言,一键安装,省时省 ...
- (一)Nginx正向代理与反向代理
引言:身为前端开发人员来说对于Nginx的作用或许很少听到,这个东西是后端使用的,Nginx对前端而言意味着什么,有什么用呢?大白会整理出几篇文章给大家细细道来. 1.正向代理的概念 正向代理,也就是 ...
- Win32 API中使用定时器的三种方法
转自:http://blog.csdn.net/fancycow/article/details/6676064 1.SetTimer(HWND,UINT,UINT,TIMERPROC);第一个参数设 ...
- 【eclipse】 怎么解决java.lang.NoClassDefFoundError错误
前言 在日常Java开 发中,我们经常碰到java.lang.NoClassDefFoundError这样的错误,需要花费很多时间去找错误的原因,具体是哪个类不见了?类 明明还在,为什么找不到?而且我 ...
- Spring IOC容器在Web容器中是怎样启动的
前言 我们一般都知道怎样使用spring来开发web应用后,但对spring的内部实现机制通常不是很明白.这里从源码角度分析下Spring是怎样启动的.在讲spring启动之前,我们先来看看一个web ...
- java 并发runable,callable,future,futureTask
转载自:http://www.cnblogs.com/dolphin0520/p/3949310.html package future_call; import java.util.concurre ...