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 ...
随机推荐
- HBase学习记录
HBase 使用docker搭建参考https://blog.csdn.net/baifanwudi/article/details/78498325 搭建好以后,网页端可以看到: terminal ...
- SpringBoot2.x整合Shiro(一)
一:什么是ACL和RBAC: ACL: Access Control List 访问控制列表 以前盛行的一种权限设计,它的核心在于用户直接和权限挂钩 优点:简单易用,开发便捷 缺点:用户和权限直接挂钩 ...
- phpredis中incr以及decr等自增命令出现的问题
在做项目中使用redis的incr以及hincrby自增时,出现自增失败,set之后的数据,无法自增,当redis中不存在该key时,直接用incr是成功的.查找了原因,是因为phpredis初始化的 ...
- 循环结构select 举例
- centos7 iperf3安装
iperf3快速安装 wget -O /usr/lib/libiperf.so.0 https://iperf.fr/download/ubuntu/libiperf.so.0_3.1.3 wget ...
- ubuntu下oracle 数据库安装
环境:腾讯云 一. 由于腾讯云直接下载oracle太慢,先安装docker 1.sudo apt update 2.接下来,使用apt安装一些允许通过HTTPS才能使用的软件包: sudo apt i ...
- Motan框架初体验
1.什么是Motan? Motan是一套基于java开发的RPC框架,除了常规的点对点调用外,motan还提供服务治理功能,包括服务节点的自动发现.摘除.高可用和负载均衡等.Motan具有良好的扩展性 ...
- StackOverflowError
"Caused by: java.lang.StackOverflowError: null",当后台出现这个报错信息的时候,证明在代码模块里面出现了死循环,但是不一定是代码的问题 ...
- 初识sed和gwak
一.sed编辑器 sed命令的格式如下: sed options script file 选项 -e script 在处理输入时,将script中指定的命令添加到已有的命令中 -f fi ...
- 大碗宽面Alpha冲刺阶段博客目录
大碗宽面Alpha冲刺阶段博客目录 一.Scrum Meeting 1. [第六周会议记录]第六周链接 2. [第七周会议记录]第七周链接 二.测试报告 [alpha阶段测试报告](博客链接) ## ...