POJ 1006 Biorhythms
来源:互联网 发布:手机淘宝网软件下载 编辑:程序博客网 时间:2024/05/01 11:58
题目:在人的生命中有三种周期:体能、情绪、智商,每种周期的周期长度分别为23,28,33,每种周期都有一天是峰顶,在相应周期的峰顶,人会在相应方面表现得最好。由于三个周期长度不同,所以三个周期的峰顶一般不在同一天。给定一个日期,我们的任务是要找出一天,这一天在三个周期中都是峰顶,称为triple peak,得到这一天到距离给定日期的天数。
输入:每一行输入一种情况,每行四个数,分别代表体能、情绪、智商三个周期的峰顶(不一定是第一个峰顶),第4个数代表给定日期。输入以 -1 -1 -1 -1结束。
输出:对每种情况,输出triple peak距离给定日期的天数,如果triple peak和给定日期是同一天,则输出下一个triple peak距离给定日期的天数。
解题思路:
1 对三个周期,分别找出一个数,这个数是另外两个周期长度的倍数,但对本周期长度取模为1。三个周期和对应的数如下:
23 --- 5544
28 --- 14421
33 --- 1288
2 对每次输入,用p,e,i,d表示三种周期的峰顶和给定日期,则
triple peak=p*5544+e*14421+i*1288
3 由于23、28、33的公倍数为21252,则triple peak对21252取模仍为一个triple peak,所以
triple peak=(p*5544+e*14421+i*1288)%21252.
4 题目要求的是triple peak距离给定日期的天数,所以triple peak必须大于d,如果triple peak小于等于d,则加一个周期公倍数21252
代码:
#include<stdio.h>int main(){int p,e,i,d,peak,count=1;scanf("%d%d%d%d",&p,&e,&i,&d);while(p!=-1 && e!=-1 && i!=-1 && d!=-1){p %= 23; e %= 28;i %= 33;if(p==e && p==i && e==i){peak = p;}else{peak = (p*5544 + e*14421 + i*1288)%21252;} if(peak <= d) peak += 21252;peak = peak -d;printf("Case %d: the next triple peak occurs in %d days.\n",count++,peak);scanf("%d%d%d%d",&p,&e,&i,&d);}return 0;}
- poj 1006 Biorhythms
- poj 1006 Biorhythms
- poj 1006 Biorhythms
- POJ 1006 Biorhythms
- POJ 1006 Biorhythms
- POJ 1006 Biorhythms
- 【POJ】1006 Biorhythms
- POJ-1006:Biorhythms
- POJ 1006 Biorhythms
- POJ 1006 Biorhythms
- POJ 1006 Biorhythms
- poj 1006 Biorhythms
- POJ 1006 Biorhythms
- Poj 1006 Biorhythms
- POJ 1006 Biorhythms
- poj 1006 hdu1370 Biorhythms
- 【POJ】1006 Biorhythms
- poj 1006 Biorhythms
- 重新安装mysql时,与之前版本冲突的处理问题
- 查看Linux内核版本的命令
- 程序打包二
- 气煞老夫 配置 PHP5ISAPI的小问题
- hibernate的Anotation的应用
- POJ 1006 Biorhythms
- hibernate执行流程
- 1213
- hibernate最初印象---helloworld的实现
- C++程序设计实验报告(四十四)---第六周任务二
- C/C++中的时间处理函数
- 《第六周实验报告任务1》
- android的AppWidget
- vs2008中switch使用一例(带测试题)