nyoj 151 Biorhythms
描述
Some people believe that there are three cycles in a person's life that start the day he or she is born. These three cycles are the physical, emotional, and intellectual cycles, and they have periods of lengths 23, 28, and 33 days, respectively. There is one peak in each period of a cycle. At the peak of a cycle, a person performs at his or her best in the corresponding field (physical, emotional or mental). For example, if it is the mental curve, thought processes will be sharper and concentration will be easier.
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.
输入
You will be given at most 1000000 cases. The input for each case consists of one line of four integers p, e, i, and d. The values p, e, and i are the number of days from the beginning of the current year at which the physical, emotional, and intellectual cycles peak, respectively. The value d is the given date and may be smaller than any of p, e, or i. All values are non-negative and at most 365, and you may assume that a triple peak will occur within 21252 days of the given date. The end of input is indicated by a line in which p = e = i = d = -1
输出
For each test case, print the number of days to the next triple peak, in the form:
样例输入
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
样例输出
21252
21152
19575
16994
8910
10789
学信安的我表示学过中国剩余定理但是做题还是不会…..
还要看别人博客才知道要用到中国剩余定理,妈卖批!!!
中国剩余定理:
基本公式为:x+d=M1*y1*p+M2*y2*e+M3*y3*i
x+d=p(mod 23);
x+d=e(mod 23);
x+d=i(mod 23);
M=23*28*33=21252,M1=924,M2=759,M3=644;
924y1=1(mod 23);
644y3=1mod 33);
(这个是由Mk*yk=1(mod mk 可以知道 至于为 什么 我还是从一 篇别人的博客里知道的 至于原因 也没有写)
可以得出来:y1=6,y2=19,y3=2;
进而:x+d=(5544*p+14421*e+1288*i)%21252;
注意:x不能是负数,所以修改为x=(5544*p+14421*e+1288*i-d+21252)%21252;
#include<cstdio>
using namespace std;
int main()
{
int p, e, i, d, icase = 0, x;
while (scanf("%d%d%d%d", &p, &e, &i, &d), ~p)
{
x = (5544 * p + 14421 * e + 1288 * i - d + 21252) % 21252;
if (x == 0)
x = 21252;
printf("%d\n",x);
}
return 0;
}
nyoj 151 Biorhythms的更多相关文章
- NYOJ 8 一种排序(comparator排序)
一种排序 时间限制: 3000 ms | 内存限制: 65535 KB 难度: 3 描述 现在有很多长方形,每一个长方形都有一个编号,这个编号可以重复:还知道这个长方形的宽和长,编号.长.宽都 ...
- NYOJ 1007
在博客NYOJ 998 中已经写过计算欧拉函数的三种方法,这里不再赘述. 本题也是对欧拉函数的应用的考查,不过考查了另外一个数论基本定理:如何用欧拉函数求小于n且与n互质所有的正整数的和. 记eule ...
- NYOJ 998
这道题是欧拉函数的使用,这里简要介绍下欧拉函数. 欧拉函数定义为:对于正整数n,欧拉函数是指不超过n且与n互质的正整数的个数. 欧拉函数的性质:1.设n = p1a1p2a2p3a3p4a4...pk ...
- poj1006 / hdu1370 Biorhythms (中国剩余定理)
Biorhythms 题意:读入p,e,i,d 4个整数,已知(n+d)%23=p; (n+d)%28=e; (n+d)%33=i ,求n . (题在文末) 知识点:中国剩余定理 ...
- NYOJ 333
http://www.cppblog.com/RyanWang/archive/2009/07/19/90512.aspx?opt=admin 欧拉函数 E(x)表示比x小的且与x互质的正整数的个数. ...
- NYOJ 99单词拼接(有向图的欧拉(回)路)
/* NYOJ 99单词拼接: 思路:欧拉回路或者欧拉路的搜索! 注意:是有向图的!不要当成无向图,否则在在搜索之前的判断中因为判断有无导致不必要的搜索,以致TLE! 有向图的欧拉路:abs(In[i ...
- nyoj 10 skiing 搜索+动归
整整两天了,都打不开网页,是不是我提交的次数太多了? nyoj 10: #include<stdio.h> #include<string.h> ][],b[][]; int ...
- NYOJ题目1080年龄排序
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAtMAAAJVCAIAAACTf+6jAAAgAElEQVR4nO3dO1Lj3NbG8W8Szj0QYg ...
- poj 1006:Biorhythms(水题,经典题,中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 110991 Accepted: 34541 Des ...
随机推荐
- Jmeter-6-创建数据库测试计划
1. 将mysql 的jdbc的jar包放到Jmeter lib的目录下. 2. 创建线程组. 3. 创建JDBC Connection Configuration, 提供详细的数据库配置信息. 4. ...
- 有关计数问题的dp
问题一:划分数 问题描述 有n个去区别的物体,将它们划分成不超过m组,求出划分方法数模M的余数. 我们定义dp[i][j],表示j的i划分的总数 将j划分成i个的话,可以先取出k个,然后将剩下的j-k ...
- java 连接MySQL的代码
1.java connect MySQL as conding. https://www.cnblogs.com/centor/p/6142775.html
- linux内存占用查看
查看内存使用情况 free free -m //显示单位为:兆 查看占用内存最高的5个进程ps aux | sort -k4nr | head -n 5 查看占用CPU最高的5个进程ps aux | ...
- 【Matlab】让Matlab程序发出声音
我有时候运行一段很长的代码,在等待的时候去做别的事,希望程序运行完可以有一个提示音. 这可以用matlab的一个函数sound实现,该函数的输入参量是音频数据向量.采样频率和转换位数. % 响一声 s ...
- Linux 入门记录:十七、Linux 命令行文本/文件处理工具
一.文件浏览 cat 查看文件内容 more 以翻页形式查看文件内容(只能向下翻页) less 以翻页形式查看文件内容(可以上下翻页) head 查看文件的头几行(默认10行) tail 查看文件的尾 ...
- (十七)vmware无法将网络更改为桥接状态
故障现象,导致虚拟机无法正常上网 设备管理器中的驱动设备正常加载,但是注意这两个虚拟网卡是有问题的 将这两个虚拟网卡删除 只剩物理网卡了,重新启动电脑 将虚拟机里的网络设置删除 清空网卡后点击恢复默认 ...
- Python爬虫数据处理
一.首先理解下面几个函数 设置变量 length()函数 char_length() replace() 函数 max() 函数1.1.设置变量 set @变量名=值 set @address='中国 ...
- 利用BeanUtils工具类封装表单数据
一.BeanUtils工具类的使用 1.首先导入BeanUtils工具类的jar包 commons-beanutils-1.8.0.jar commons-logging-1.1.1.jar 2.se ...
- hdu 1026(优先队列+路径输出)
Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...