算法练习之: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
随机推荐
- 使用WebView显示网页
简单的页面跳转 package com.example.webtest; import java.security.PublicKey; import android.support.v7.app.A ...
- linux网卡混杂模式打开
有时候为嗅探到网络上的数据,需要将网卡设置到混杂模式.进入该模式将网络上的数据一并抓获,为此在设置nic的混杂模式的时候有诸多方法? 通过shell命令来实现:ifconfig eth1 promis ...
- Redis操作字符串工具类封装,Redis工具类封装
Redis操作字符串工具类封装,Redis工具类封装 >>>>>>>>>>>>>>>>>>& ...
- html代码实现自动滚动,鼠标滑过时停止滚动
<marquee style="width: 1200px;height:200px;margin:0px auto" onmouseout="this.start ...
- JQuery AJAX请求aspx后台方法
利用JQuery封装好的AJAX来请求aspx的后台方法,还是比较方便的,但是要注意以下几点: 1.首先要在方法的顶部加上[WenMethod]的特性(此特性要引入using System.Web.S ...
- magento addFieldToFilter()方法常用的过滤条件
记录一下Magento模型集合Model Collection中addFieldToFilter()方法常用的过滤条件.以下参数也同样适用于产品实体的addAttributeToFilter()方法. ...
- HDU-1034(简单模拟)
Candy Sharing Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- xcode编译运行报错纪录(持续更新)
---恢复内容开始--- 1. Undefined symbols for architecture i386: "_deflate", referenced from: -[NS ...
- 09_Mybatis开发Dao方法——mapper代理开发规范
一.开发规范 需要编写mapper.xml映射文件(本项目为userMapper.xml,类似于前面的user.xml). 编写mapper接口需要遵循一些开发规范,这样MyBatis可以自动生成ma ...
- autoplay media studio couldn't load
AutoPlay Media Studio 7 (English version) is installed on target machine. Following error occurred w ...