Biorhythms
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 135099 | Accepted: 43146 |
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. 题目长,题意是:给出 p,e,i,d ,已知 (n+d)%23 == p ,(n+d)%28 == e , (n+d)%33 == i ,求 n (N>0)
暴力即可,写一下记录中国剩余定理,又名孙子定理
解法:
已知(n+d)%23=p; (n+d)%28=e; (n+d)%33=i
使28×33×a被23除余1,用33×28×8=5544;
使23×33×b被28除余1,用23×33×19=14421;
使23×28×c被33除余1,用23×28×2=1288。
所以:(5544×p+14421×e+1288×i)% lcm(23,28,33) = n+d
23、28、33互质,即lcm(23,28,33)= 21252;
得式子:n=(5544×p+14421×e+1288×i-d+lcm)%lcm
其实也就是凑出来这个数字
暴力的:
#include <iostream>
#include <stdio.h> using namespace std;
#define MAX 21252 int main()
{
int a,b,c,d;
int cas=;
while (scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF)
{
if (a==-&&b==-&&c==-&&d==-)
break;
a%=;
b%=;
c%=;
for (int i=c;i<=MAX+;i+=)
{
if ((i-a)%== && (i-b)%== && (i-c)%==)
{
if (i<=d)
i+=MAX;
printf("Case %d: the next triple peak occurs in %d days.\n",cas++,i-d);
break;
}
}
}
return ;
}
定理的: 快一些
#include <iostream>
#include <stdio.h>
using namespace std; int main()
{
int p,e,i,d;
int cas=;
while (scanf("%d%d%d%d",&p,&e,&i,&d)!=EOF)
{
if (p==-&&e==-&&i==-&&d==-) break; int n=(*p+*e+*i-d+)%;
if (n==) n+=;
printf("Case %d: the next triple peak occurs in %d days.\n",cas++,n);
}
return ;
}
Biorhythms的更多相关文章
- poj1006 / hdu1370 Biorhythms (中国剩余定理)
Biorhythms 题意:读入p,e,i,d 4个整数,已知(n+d)%23=p; (n+d)%28=e; (n+d)%33=i ,求n . (题在文末) 知识点:中国剩余定理 ...
- poj 1006:Biorhythms(水题,经典题,中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 110991 Accepted: 34541 Des ...
- POJ 1006 - Biorhythms (中国剩余定理)
B - Biorhythms Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Subm ...
- [POJ] #1006# Biorhythms : 最小公倍数/同余问题
一. 题目 Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 127263 Accepted: 403 ...
- Poj 1006 / OpenJudge 2977 1006 Biorhythms/生理周期
1.链接地址: http://poj.org/problem?id=1006 http://bailian.openjudge.cn/practice/2977 2.题目: Biorhythms Ti ...
- 算法练习之:Biorhythms
Biorhythms Time Limit: 1000MS Memory Limit: 10000KB Problem Description Some people believe that th ...
- Biorhythms(中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 127339 Accepted: 40342 Des ...
- POJ - 1006 Biorhythms 周期相遇 两个思路程序
Description Some people believe that there are three cycles in a person's life that start the day he ...
- Biorhythms(poj1006+中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 117973 Accepted: 37026 Des ...
- Biorhythms(中国剩余定理)
http://shuxueshi.jie.blog.163.com/blog/static/13611628820104179856631/ 这篇博客写的很棒! #include<stdio.h ...
随机推荐
- office2010使用mathtype时,出现未找到MathPage.WLL解决方案--亲测有用
安装mathtype时,出现如下错误: 解决方案: 参考此网址中的内容:http://www.mathtype.cn/wenti/word-jianrong.html 首先需要找到在Word加载的两个 ...
- SWIG 多语言接口变换 【转】
一. SWIG 是Simple Wrapper and Interface Generator的缩写,是一个帮助使用C或者C++编写的软件创建其他编语言的API的工具.例如,我 ...
- IDETalk
IDETalk插件下载地址 IDETalk是由JetBrains的工程师开发的一款代码级的协同工具,主要是为一个团队在进行相关项目开发时提供代码协同.当前IDETalk只能运行在IDEA下,你可以通过 ...
- 查找文件命令find总结以及查找大文件
find / -name *** 示例如下: [dinpay@zk-spark-01 spark]$ find /home/ll -name slaves /home/ll/spark/conf/sl ...
- tomcat修改默认访问首页
找到conf下server.xml文件修改如下位置内容 <Host name="localhost" appBase="webapps" unpackWA ...
- 【Android高级】NDK/JNI编程技术基础介绍
作为一个Andoird的Java程序猿,会受到Java语言的局限.由于作为一面门向对象的语言不能像C/C++那样轻易调用与硬件有关的操作.因此JNI就搭建了这样一个桥梁,使Java和C/C++语言之间 ...
- #include <>与#include""区别
<>先去系统目录中找头文件,如果没有在到当前目录下找.所以像标准的头文件 stdio.h.stdlib.h等用这个方法. 而""首先在当前目录下寻找,如果找不到,再到系 ...
- HBase伪分布式安装及简单使用
HBase是Hadoop的数据库,基于Hadoop执行.是一种NoSQL数据库. 特点:分布式.多版本号.面向列的存储模型.可以大规模的数据实时随机读写,可直接使用本地文件系统. 不适合:与关系型数据 ...
- 【Shell】Read命令
read命令从键盘读取变量的值,通常用在shell脚本与用户进行交互的场合.该命令可以一次性读取多个变量的值,变量的输入和输出需要使用空格隔开.在read命令后面,如果没有指定变量名,读取的数据将被自 ...
- jenkins插件安装失败更改插件源
看提示的日志说是下载失败,应该是网络问题 最好的办法就是更改下载源 [系统管理][管理插件][高级]升级站点项的的地址修改成 修改之后,安装了一下git的插件速度非常快,jenkins镜像地址列表ht ...