[POJ 1006]生理周期
Description
Input
当p = e = i = d = -1时,输入数据结束。
Output
采用以下格式:
Case 1: the next triple peak occurs in 1234 days.
注意:即使结果是1天,也使用复数形式“days”。
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.
题解
就是求同余方程组
$$ \left\{
\begin{aligned}
x &\equiv p &\pmod {23} \\
x &\equiv e &\pmod {28} \\
x &\equiv i &\pmod {33}
\end{aligned}
\right.
$$
大于$d$的最小正整数解。(喻队)孙子定理乱搞就好了。
//It is made by Awson on 2017.10.29
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Abs(x) ((x) < 0 ? (-(x)) : (x))
using namespace std;
const int MOD = **; int a[], m[] = {, , , }, n = , d;
int casecnt; int ex_gcd(int a, int b, int &x, int &y) {
if (b == ) {
x = , y = ; return a;
}
int gcd = ex_gcd(b, a%b, x, y);
int t = x;
x = y;
y = t-a/b*y;
return gcd;
}
int inv(int a, int b) {
int x, y;
ex_gcd(a, b, x, y);
return (x%b+b)%b;
}
int CRT() {
int M = , ans = ;
for (int i = ; i <= n; i++) M *= m[i];
for (int i = ; i <= n; i++)
(ans += a[i]*(M/m[i])*inv(M/m[i], m[i])) %= M;
return (ans+M)%M;
}
void work() {
casecnt++;
if (d == -) return;
int ans = CRT();
if (ans <= d) ans += MOD-d;
else ans -= d;
printf("Case %d: the next triple peak occurs in %d days.\n", casecnt, ans);
}
int main() {
while (~scanf("%d%d%d%d", &a[], &a[], &a[], &d)) work();
return ;
}
[POJ 1006]生理周期的更多相关文章
- POJ 1006 生理周期(中国剩余定理)
POJ 1006 生理周期 分析:中国剩余定理(注意结果要大于d即可) 代码: #include<iostream> #include<cstdio> using namesp ...
- POJ 1006 生理周期【数论】
这题是有中文版的(右上角选项卡里把default改成简体中文)然后看到他把biorhythms翻成生理周期我可耻的笑了......23333 如果没有限定从日期d开始,完全可以从第一天起开始计时,因此 ...
- poj——1006 生理周期
生理周期 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 138291 Accepted: 44300 Descripti ...
- poj 1006 生理周期(中国剩余定理)
题目 题目有中文翻译,自行查看. 中国剩余定理,基础的,但是我最早还是一窍不通,后来看了各种网上的博客上的相关解析,终于有点懂了,下面这个链接是让我懂得蛮多的一个博客,虽然大体上和其他的差不多. 代码 ...
- POJ - 1006 Biorhythms 周期相遇 两个思路程序
Description Some people believe that there are three cycles in a person's life that start the day he ...
- 生理周期POJ 1006
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 138101 Accepted: 44225 Description 人生 ...
- POJ 1006 - Biorhythms (中国剩余定理)
B - Biorhythms Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Subm ...
- poj 1006 Biorhythms (中国剩余定理模板)
http://poj.org/problem?id=1006 题目大意: 人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这 ...
- [POJ 1006] Biorhythms C++解题
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 107569 Accepted: 33365 ...
随机推荐
- 网络1712--c语言嵌套循环作业总结
1.助教有话说 首先,每周一篇的博客作业是很有必要的:编程的过程不仅仅是会敲几行代码.能够通过PTA就大吉大利了,你更应该做到的是梳理代码思路,通过与他人代码思路的比对,取其精华,进而不断进阶,才能逐 ...
- 《团队-OldNote-项目总结》
我们小组做的是手机便签的app---OldNote 最开始我们想解决普通手机便签无法进行语音和照片的备忘这一问题,但是由于没有做过拍照和录音的经验怕由于技术原因无法达成目的,就没敢写在需求分析中.当完 ...
- Beta Scrum Day 4
听说
- MySQL 操作详解
MySQL 操作详解 一.实验简介 本节实验中学习并实践 MySQL 上创建数据库.创建表.查找信息等详细的语法及参数使用方法. 二.创建并使用数据库 1. 创建并选择数据库 使用SHOW语句找出服务 ...
- bzoj千题计划276:bzoj4515: [Sdoi2016]游戏
http://www.lydsy.com/JudgeOnline/problem.php?id=4515 把lca带进式子,得到新的式子 然后就是 维护树上一次函数取min 一个调了一下午的错误: 当 ...
- SUN平台服务器光纤共享存储互斥失败如何恢复数据?
服务器数据恢复故障描述: 服务器最初的设计思路为将两台SPARC SOLARIS系统通过光纤交换机共享同一存储作为CLUSTER使用,正常情况下A服务器工作,当A服务器发生故障宕机后即可将其关机然后开 ...
- nyoj 苹果
苹果 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 ctest有n个苹果,要将它放入容量为v的背包.给出第i个苹果的大小和价钱,求出能放入背包的苹果的总价钱最大值. ...
- GitHub 上下载单个文件夹
写代码的一定经常去github上查看.下载一些源码,有时候会想下载一个项目中的一个文件夹里的内容,但是github上只提供了整个项目的下载,而整个项目里东西太多,压缩的文件太大,github的下载速度 ...
- [JCIP笔记] (二)当我们谈线程安全时,我们在谈论什么
总听组里几个大神说起线程安全问题.本来对"线程安全"这个定义拿捏得就不是很准,更令人困惑的是,大神们用这个词指代的对象不仅抽象而且千变万化.比如,我们的架构师昨天说: " ...
- wamp的mysql设置用户名和密码
wamp下修改mysql root用户的登录密码 感谢作者:http://www.3lian.com/edu/2014/02-25/131010.html 1.安装好wam ...