[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 ...
随机推荐
- (译文)掌握JavaScript基础--理解this关键字的新思路
普通函数 下面这种就是普通函数 function add(x, y) { return x + y; } 每个普通函数被调用的时候,都相当于有一个this参数传进来. 内部函数this不会是外部函数传 ...
- C语言程序设计(基础)- 第7周作业
为了防止误解,自从本周开始ppt.pta作业.博客作业的命名均与学校教学周一致. 要求一(20经验值) 完成PTA中题目集名为<usth-C语言基础-第七周作业>和<usth-C语言 ...
- 201621123060《JAVA程序设计》第三周学习总结
1. 本周学习总结 1.1写出你认为本周学习中比较重要的知识点关键词,如类.对象.封装等. 关键词:类.方法.属性.对象.多态.继承.封装.面向对象.> 1.2 用思维导图或者Onenote或其 ...
- node.js基础
//安装淘宝npm镜像 npm install -g cnpm --registry=https://registry.npm.taobao.org//require表示引包,引包就是引用自己的一个特 ...
- python的PEP8 代码风格指南
PEP8 代码风格指南 这篇文章原文实际上来自于这里:https://www.python.org/dev/peps/pep-0008/ 知识点 代码排版 字符串引号 表达式和语句中的空格 注释 版本 ...
- 如何书写高效的css样式
如何书写高效的css样式? 有以下四个关键要素: 1.高效的css 2.可维护的css 3.组件化的css 4.hack-free css 书写高效的css: 1.使用外联样式替代行间样式或内嵌样式 ...
- PV & PVC - 每天5分钟玩转 Docker 容器技术(150)
Volume 提供了非常好的数据持久化方案,不过在可管理性上还有不足. 拿前面 AWS EBS 的例子来说,要使用 Volume,Pod 必须事先知道如下信息: 当前 Volume 来自 AWS EB ...
- RocketMQ(二):RPC通讯
匠心零度 转载请注明原创出处,谢谢! RocketMQ网络部署图 NameServer:在系统中是做命名服务,更新和发现 broker服务. Broker-Master:broker 消息主机服务器. ...
- linux下面的智能解压脚本smart解压
file命令可以辨别出一个给定文件的文件类型,如:file lf.gz,其输出结果为: lf.gz: gzip compressed data, deflated, original filename ...
- gradle入门(1-1)gradle的概念和使用
一.Gradle是什么 Gradle是一种Java应用构建工具,它采用领域特定语言 Groovy 语法实现配置. 1.Gradle的基本概念 项目:项目的配置 即 build.gradle. 任务:任 ...