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 ...
随机推荐
- codeforces contest 864 problemD
Ivan has an array consisting of n elements. Each of the elements is an integer from 1 to n. Recently ...
- 【51NOD-5】1293 球与切换器
[算法]DP [题解]f[i][j][0]表示在i,j位置往下走的球数,f[i][j][1]表示在i,j位置往右走的球数,经过i,j的球若为-1则(num+1)/2往下,其余往右.+1类似. 转移见代 ...
- 【POJ】2892 Tunnel Warfare
[算法]平衡树(treap) [题解]treap知识见数据结构 在POJ把语言从G++换成C++就过了……??? #include<cstdio> #include<algorith ...
- HDU 1465 不容易系列之一 (错排公式+容斥)
题目链接 Problem Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好"一件"事情尚且不易,若想永远成功而总从不失败,那更是难上 ...
- HDU 1372 Knight Moves (广搜)
题目链接 Problem Description A friend of you is doing research on the Traveling Knight Problem (TKP) whe ...
- 【bug】vue-cli 3.0报错的解决办法
先上bug图片 bug说明:初装vue_cli3.0写了个组件,运行错误,显示如图, 代码提示:[Vue warn]: You are using the runtime-only build of ...
- PKUWC 2019 自闭记
PKUWC 2019 自闭记 Day -1 考前天天在隔壁的物竞教室划水(雀魂,能和吉老师一起玩的游戏都是好游戏),没有做题. Day 0 早上8:16的高铁,到广州南居然要6个小时...不知道福州和 ...
- 第一章:获取服务器服务banner
#!c:\\perl\\bin\\perl.exe #读取服务器的首行(banner) use IO::Socket; my $service = '121.201.67.177:ssh'; my $ ...
- node启动服务
npm install http-server -g http-server ipconfig查看当前ip 手机可访问第一个网址.
- python基础===基于requests模块上的协程【trip】
今天看博客get了一个有趣的模块,叫做 trip #(pip install trip) 兼容2.7版本 基于两大依赖包:TRIP: Tornado & Requests In Pa ...