算法练习之:Biorhythms
Biorhythms
Problem 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.
Example 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
Example 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>
int main(int argc, const char * argv[]){
int physical, emotional, intellectual, date;
int physicalCycle = , emotionalCycle = , intellectualCycle = , LCM = ;
int caseIndex = ;
while (scanf("%d %d %d %d", &physical, &emotional, &intellectual, &date)) {
if (physical < || emotional < || intellectual < || date <) break;
caseIndex ++;
physical ? physical = physical % physicalCycle : NULL;
emotional ? emotional = emotional % emotionalCycle : NULL;
intellectual ? intellectual = intellectual % intellectualCycle : NULL; int i = , temp;
while () {
temp = i * intellectualCycle + intellectual;
if ((temp % physicalCycle == physical) && (temp % emotionalCycle == emotional)) break;
i++;
}
temp = temp <= date ? temp + LCM : temp;
temp -= date;
printf("Case %d: the next triple peak occurs in %d days.\n", caseIndex, temp);
}
return ;
}//0ms 108kb g++ 1047B
算法练习之:Biorhythms的更多相关文章
- [POJ] #1006# Biorhythms : 最小公倍数/同余问题
一. 题目 Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 127263 Accepted: 403 ...
- Biorhythms(中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 127339 Accepted: 40342 Des ...
- 算法之路 level 01 problem set
2992.357000 1000 A+B Problem1214.840000 1002 487-32791070.603000 1004 Financial Management880.192000 ...
- B树——算法导论(25)
B树 1. 简介 在之前我们学习了红黑树,今天再学习一种树--B树.它与红黑树有许多类似的地方,比如都是平衡搜索树,但它们在功能和结构上却有较大的差别. 从功能上看,B树是为磁盘或其他存储设备设计的, ...
- 分布式系列文章——Paxos算法原理与推导
Paxos算法在分布式领域具有非常重要的地位.但是Paxos算法有两个比较明显的缺点:1.难以理解 2.工程实现更难. 网上有很多讲解Paxos算法的文章,但是质量参差不齐.看了很多关于Paxos的资 ...
- 【Machine Learning】KNN算法虹膜图片识别
K-近邻算法虹膜图片识别实战 作者:白宁超 2017年1月3日18:26:33 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现的深入理解.本系列文章是作者结 ...
- 红黑树——算法导论(15)
1. 什么是红黑树 (1) 简介 上一篇我们介绍了基本动态集合操作时间复杂度均为O(h)的二叉搜索树.但遗憾的是,只有当二叉搜索树高度较低时,这些集合操作才会较快:即当树的高度较高(甚至一种极 ...
- 散列表(hash table)——算法导论(13)
1. 引言 许多应用都需要动态集合结构,它至少需要支持Insert,search和delete字典操作.散列表(hash table)是实现字典操作的一种有效的数据结构. 2. 直接寻址表 在介绍散列 ...
- 虚拟dom与diff算法 分析
好文集合: 深入浅出React(四):虚拟DOM Diff算法解析 全面理解虚拟DOM,实现虚拟DOM
随机推荐
- Bootstrap--组件之下拉菜单
用于显示链接列表的可切换.有上下文的菜单. 对齐 B默认情况下,下拉菜单自动沿着父元素的上沿和左侧被定位为 100% 宽度. 为 .dropdown-menu 添加 .dropdown-menu-ri ...
- JVM内存模型以及垃圾收集策略解析
http://xmuzyq.iteye.com/blog/599750 一 JVM内存模型 1.1 Java栈 Java栈是与每一个线程关联的,JVM在创建每一个线程的时候,会分配一定的栈空间给线程. ...
- Extjs combobox设置默认值
转载:http://www.54mask.com/extjs-combobox-default-value.html 相信很多人都遇到了在ExtJS框架中设置combo组件默认值的需求,ExtJS框架 ...
- JavaScript学习笔记 -- ES6学习(三) 变量的解构赋值
1.解构赋值的定义 在ES6中,允许按照一定模式,从数组和对象中提取值(所谓解构),然后对变量进行赋值. var a = 1; var b = 2; var c = 3; //等价于 var [a, ...
- redis基本数据类型【2】-Hash类型
一.概述 1.散列是一种典型的字典结构,filed和value的映射,但value只能存储字符串,不支持其他类型 2.一个散列类型最多包含 2^32 -1个字段 3.散列适合存储对象:使用对象和ID构 ...
- Codevs 2597 团伙(并查集)
2597 团伙 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 传送门 题目描述 Description 1920年的芝加哥,出现了一群强盗.如果两个强盗遇上了,那么 ...
- c++ primer复习(三)
1 istream.ostream类型,cin.cout.cerr是istream或ostream类型的具体的对象,<<和>>是操纵符 getline函数的参数是istream ...
- IOS 学习笔记 2015-03-20 O之 nil,Nil,NULL,NSNull
1.oc最好 用nil [ nil 任意方法],不会崩溃 nil 是一个对象值.NULL是一个通用指针(泛型指针). 2. NSNULL,NULL和nil在本质上应该是一样的,NULL和nil其 ...
- linux下shell编程示例-获取进程id
今天初步学习了一下linux下的shell编程,简单记录一下测试用例 1.编辑shell脚本文件如下: #!/bin/bashecho "hello bash linux"echo ...
- [翻译][MVC 5 + EF 6] 3:排序、过滤、分页
原文:Sorting, Filtering, and Paging with the Entity Framework in an ASP.NET MVC Application 1.添加排序: 1. ...