1006 -- Biorhythms
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 138926 | Accepted: 44590 |
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. 好吧!题名就把我唬住了,没见过的单词啊。 没事,google一下。
哈! 还是不懂啥意思。 算了,直接看题目。
题目说 : 有些人认为啊,从人一出生开始,有三个周期就开始运转了,啥周期呢?身体、情感和智力周期。 它们的周期时长分别是23天,28天,33天。 然后呢,它们都会有一个顶峰嘛,在这个顶峰的时候,我们相对应的表现就会很牛逼。比如,如果是心理曲线,思考会更快,而且更容易集中。
又因为呢,这三个周期的顶峰不一样,通常都会在不同的时间出现。 然后呢,我们现在想算一下,哪一天是三个顶峰同时出现(三buff齐加,上天了)。现在给出三个日期,分别对应于体力,情感,智力离今年第一天出现峰值的日期。然后再给出一个起始日期,要求从这一天开始,算出最少再过多少天后三个峰值同时出现。 解题: 我们假设这三个周期都是正弦波,画个图出来看看。
图画得非常丑啊! 但是没关系,我们来看,要三buff齐开,就是要刚好三个顶峰凑在一起了。 假设我们已经知道了,三个顶峰将会在S天后出现,那么,S = N1 + T1*K1 = N2 + T2*K2= N3 + T3*K3。 N是指单一顶峰出现的时间,T代表周期,K是正整数。
那我们现在有一种简单的做法,穷举! 先试试。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T1 = 23;
int T2 = 28;
int T3 = 33;
int count = 0;
while(scanner.hasNext()){
count++;
int N1 = scanner.nextInt();
int N2 = scanner.nextInt();
int N3 = scanner.nextInt();
int C = scanner.nextInt();
if(N1 ==-1 && N2 ==-1 && N3 == -1 && C==-1){
return;
}
for(int i = 1 ; i <= 21252+C ;i++){
if((i-N1)%T1==0){
}else{
continue;
}
if((i-N2)%T2==0){
}else{
continue;
}
if((i-N3)%T3==0){
}else{
continue;
}
if(i-C<=0){
continue;
}
System.out.println("Case "+count+": the next triple peak occurs in "+(i-C)+" days.");
break;
}
}
}
}
OK! 穷举的代码得出正确结果。 可是。。。。 超时了。 好~ 不用这么拙劣的办法。我们先来看看,中国剩余定理!
看完之后我们再来解题, S = N1 + T1*K1 = N2 + T2*K2= N3 + T3*K3
我们可以拆解成 :
S%T1 = N1 ,
S%T2 = N2 ,
S%T3 = N3.
这样就可以用中国剩余定理了。
1006 -- Biorhythms的更多相关文章
- POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理)
POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理) 题意分析 不妨设日期为x,根据题意可以列出日期上的方程: 化简可得: 根据中国剩余定理求解即可. 代码总览 #include & ...
- POJ 1006 - Biorhythms (中国剩余定理)
B - Biorhythms Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Subm ...
- Poj 1006 / OpenJudge 2977 1006 Biorhythms/生理周期
1.链接地址: http://poj.org/problem?id=1006 http://bailian.openjudge.cn/practice/2977 2.题目: Biorhythms Ti ...
- poj 1006:Biorhythms(水题,经典题,中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 110991 Accepted: 34541 Des ...
- [POJ] #1006# Biorhythms : 最小公倍数/同余问题
一. 题目 Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 127263 Accepted: 403 ...
- POJ 1006 Biorhythms(中国剩余定理)
题目地址:POJ 1006 学习了下中国剩余定理.參考的该博客.博客戳这里. 中国剩余定理的求解方法: 假如说x%c1=m1,x%c2=m2,x%c3=m3.那么能够设三个数R1,R2,R3.R1为c ...
- POJ - 1006 Biorhythms 周期相遇 两个思路程序
Description Some people believe that there are three cycles in a person's life that start the day he ...
- poj 1006 Biorhythms (中国剩余定理模板)
http://poj.org/problem?id=1006 题目大意: 人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这 ...
- POJ 1006 Biorhythms --中国剩余定理(互质的)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 103539 Accepted: 32012 Des ...
- [POJ 1006] Biorhythms C++解题
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 107569 Accepted: 33365 ...
随机推荐
- Python开发简介
年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC语言的一种继承 . 最新的TIOBE排行榜,Python已经占据世界第四名的位置, Python崇尚优美 ...
- XX-net 3.11.9 登陆Google等出现没有开启cookie的问题
糟糕!您的浏览器似乎禁用了 Cookie.请务必启用 Cookie 或尝试打开一个新的浏览器窗口. 出现这个问题解决方法: 1.配置好X-tunnel,即登录账号2.打开谷歌浏览器或者你用的浏览器,设 ...
- SPI、IIC、IIS、UART、JTAG的应用场合级区别
SPI SPI接口的全称是"Serial Peripheral Interface",意为串行外围接口,是Motorola首先在其MC68HCXX系列处理器上定义的. SPI接口 ...
- java并发编程之美-阅读记录11
java并发编程实践 11.1ArrayBlockingQueue的使用 有关logback异步日志打印中的ArrayBlockingQueue的使用 1.异步日志打印模型概述 在高并发.高流量并且响 ...
- PHP应该学什么,如何学好PHP
http://blog.sina.com.cn/s/blog_76bdabf70101azl4.html(注:原文来自传智播客) 本文转自http://blog.sina.com.cn/s/blog_ ...
- go语言从例子开始之Example10.map(字典)
map 是 Go 内置关联数据类型(在一些其他的语言中称为哈希 或者字典 ) package main import "fmt" func main() { 要创建一个空 map, ...
- linux 出现 -bash-4.2# 问题的解决方法
1.在根目录创建 /root 目录 mkdir /root 2. 复制 .bashrc 以及 .bash_profile俩个文件到root目录下 cp /etc/skel/.bashrc /root ...
- 启动ABP项目
1.在官网下载ABP项目 2.打开项目选择解决方案,右击还原NuGet包 3.修改appsettings.json中的ConnectionStrings 例子"ConnectionStrin ...
- Python 获取当前文件所在路径
记录几个os获取路径的函数 1. os.path.realpath(__file__):获取文件的绝对路径,包括文件自己的名字 2.os.path.dirname(path):获取path路径的上级路 ...
- 2018/8/26学习Mysql笔记
SELECT * FROM product; #.基本增删改查 #新增 #需求:添加一条数据到产品表 产品名称为苹果手机 卖价为5000 ); #删除 #需求:删除产品表中id=20的数据 ; #需求 ...