hdu 1370 || poj 1006 简单的中国剩余定理或者暴力
Biorhythms
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
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.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Case 1: the next triple peak occurs in 1234 days.
Use the plural form ``days'' even if the answer is 1.
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
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<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 999999999
//#pragma comment(linker, "/STACK:102400000,102400000")
int scan()
{
int res = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
return res ;
}
int a[];
int b[];
int gcd(int x,int y)
{
if(x%y==)
return y;
else
return gcd(y,x%y);
}
void exgcd(int a, int b, int &x, int &y)
{
if(b == )
{
x = ;
y = ;
return;
}
exgcd(b, a % b, x, y);
int tmp = x;
x = y;
y = tmp - (a / b) * y;
}
int check()
{
for(int i=;i<;i++)
if(a[i]!=-)
return ;
return ;
}
int main()
{
int x,y,z,i,t;
scanf("%d",&x);
while(x--)
{
int flag=;
while()
{
z=;
b[]=;
b[]=;
b[]=;
for(i=;i<z;i++)
scanf("%d",&a[i]);
if(!check())
break;
int a1=a[],b1=b[];
//int jie=1;
for(i=;i<z-;i++)
{
int a2=a[i],b2=b[i];
int xx,yy;
int gys=gcd(b1,b2);
/*if((a2-a1)%gys)
{
jie=0;
break;
}*/
exgcd(b1,b2,xx,yy);
xx=(xx*(a2-a1))/gys;
int gbs=b1*b2/gys;
a1=(((xx*b1+a1)%gbs)+gbs)%gbs;
b1=gbs;
}
a1-=a[];
if(a1<=)
a1+=b1; printf("Case %d: the next triple peak occurs in %d days.\n",flag++,a1);
}
}
return ;
}
hdu 1370 || poj 1006 简单的中国剩余定理或者暴力的更多相关文章
- POJ 1006 生理周期(中国剩余定理)
POJ 1006 生理周期 分析:中国剩余定理(注意结果要大于d即可) 代码: #include<iostream> #include<cstdio> using namesp ...
- poj 1006 Biorhythms (中国剩余定理模板)
http://poj.org/problem?id=1006 题目大意: 人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这 ...
- POJ 1006 Biorhythms (中国剩余定理)
在POJ上有译文(原文右上角),选择语言:简体中文 求解同余方程组:x=ai(mod mi) i=1~r, m1,m2,...,mr互质利用中国剩余定理令M=m1*m2*...*mr,Mi=M/mi因 ...
- POJ 1006 Biorhythnms(中国剩余定理)
http://poj.org/problem?id=1006 题意: (n+d) % 23 = p ;(n+d) % 28 = e ;(n+d) % 33 = i ; 求最小的n. 思路: 这道题就是 ...
- hdu 1573 X问题【扩展中国剩余定理】
扩展中国剩余定理的板子,合并完之后算一下范围内能取几个值即可(记得去掉0) #include<iostream> #include<cstdio> #include<cm ...
- HDU 6463.超级无敌简单题-卡边界的暴力 (“字节跳动-文远知行杯”广东工业大学第十四届程序设计竞赛)
超级无敌简单题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- HDU 3268/POJ 3835 Columbus’s bargain(最短路径+暴力枚举)(2009 Asia Ningbo Regional)
Description On the evening of 3 August 1492, Christopher Columbus departed from Palos de la Frontera ...
- poj 2891 Strange Way to Express Integers(中国剩余定理)
http://poj.org/problem?id=2891 题意:求解一个数x使得 x%8 = 7,x%11 = 9; 若x存在,输出最小整数解.否则输出-1: ps: 思路:这不是简单的中国剩余定 ...
- POJ1006 - Biorhythms(中国剩余定理)
题目大意 略...有中文... 题解 就是解同余方程组 x≡(p-d)(mod 23) x≡(e-d)(mod 28) x≡(i-d)(mod 33) 最简单的中国剩余定理应用.... 代码: #in ...
随机推荐
- 2018-2019-2 网络对抗技术 20165324 Exp3:免杀原理与实践
2018-2019-2 网络对抗技术 20165324 Exp3:免杀原理与实践 免杀原理及基础问题回答 免杀 1. 一般是对恶意软件做处理,让它不被杀毒软件所检测.也是渗透测试中需要使用到的技术. ...
- 7.10 Models -- Handling Metadata(处理元数据)
1. 随着从store中返回的records,你可能需要处理一些元数据.Metadata是伴随着特定model或者type的一种数据,而不是record. 2. 分页是使用元数据的一个常见的例子.想象 ...
- AI-Tank
编程,就是编写人生,你的思维越好,就的生活就会充满乐趣,不多说了,下面来讲一个游戏. 讲游戏的开始,要说一点,游戏可以玩,不能沉溺.不然人的一生就会沦陷进去. 下面讲一个使用的代码游戏. 在玩游戏的时 ...
- OAuth 白话简明教程 2.授权码模式(Authorization Code)
转自:http://www.cftea.com/c/2016/11/6703.asp OAuth 白话简明教程 1.简述 OAuth 白话简明教程 2.授权码模式(Authorization Code ...
- 神经网络 java包
java神经网络组件Joone.Encog和Neuroph https://github.com/deeplearning4j/deeplearning4j http://muchong.com/ht ...
- Visual Studio 2013旗舰版KEY
Visual Studio 2013旗舰版KEY:BWG7X-J98B3-W34RT-33B3R-JVYW9
- vs2013中将原来在iis express中的网站转到iis中时,报“无法在web服务器上调试”的解决方法
之前在网上也搜索过,但没有一个是正确的,后来在微软网站上发现问题的解决方法: 在web.config中,打开调试就可以了,具体方法为: 在web.config中 在以下配置节中加入以下代码 <c ...
- python recv()是什么
socket有个recv方法,recv有一个参数,指定数据缓冲区的大小 但是现在的问题就是不知道将要接受的数据的大小到底是多少,可能只有几个字节,可能会有几M,google了一下socket的入门文章 ...
- php 写内容到文件,把日志写到log文件
php 写内容到文件,把日志写到log文件 <?php header("Content-type: text/html; charset=utf-8"); /******** ...
- 02: python3使用email和smtplib库发送邮件
1.1 发送qq邮箱 注:python代理登录qq邮箱发邮件,是需要更改自己qq邮箱设置的.在这里大家需要做两件事情:邮箱开启SMTP功能 .获得授权码 教程链接 1.给单个人发邮件 参考 from ...