[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 ...
随机推荐
- 听翁恺老师mooc笔记(3)--指针的定义
在上一个blog学习了&运算符,使用&取了变量.数组等地址,有什么用那?如果能够将取得的变量的地址传递给函数,能否通过这个地址在函数内访问到外部这个变量?答案是肯定的,scanf(&q ...
- 实验四:Android 开发基础
实验四:实验报告 课程:程序设计与数据结构 班级: 1623 姓名: 张旭升 学号:20162329 指导教师:娄嘉鹏 王志强 实验日期:5月26日 实验密级: 非密级 预习程度: 已预习 必修/选修 ...
- 从0开始的LeetCode生活—9. Palindrome Number(回文数)
题目大意: 判断输入的数字是不是回文数.所谓回文数就是正反读都一样的数字,比如说11,121,1221这样子的数字.负数不会是回文数. 解题思路: 思路一:如果这个数是负数,则返回false,否则用一 ...
- 团队开发---”我爱淘“校园二手书店 NABC分析
本项目特点之一:可预订 N:对于一些抢手的书可以提前预定,避免学生买不到书 A:网上下单,通过手机便捷购物 B:使得订书更加方便快捷 C:二手书摊.网上书店 团队成员:杨广鑫.郭健豪.李明.郑涛
- 在深度linux下安装pip3与jupyter
前言 以下安装说明基于已经正确安装python3 文件下载 https://pypi.python.org/pypi/pip 下载pip-9.0.1.tar.gz (md5, pgp)文件 安装准备工 ...
- REST or RPC?
1 概念 1.1 RPC RPC(Remote Procedure Call)-远程过程调用,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议.RPC协议假定某些传输协议的存 ...
- 从同步阻塞聊到Java三种IO方式
本文总结自 https://zhuanlan.zhihu.com/p/34408883, https://www.zhihu.com/question/19732473中愚抄的回答, http://b ...
- 我的前端故事----来聊聊react-native应用的健康监控
监控什么 今天我们来聊聊如何监控你的应用程序,这里的监控说的不是让我们去监控用户,而是监控应用的健康状态,什么是健康状态呢?对于后端的同学来说,在微服务的架构下,每个子服务是否正常工作.返回的结果是否 ...
- MySQL 避免重复数据的批量插入与批量更新
[转发] 导读 我们在向数据库里批量插入数据的时候,会遇到要将原有主键或者unique索引所在记录更新的情况,而如果没有主键或者unique索引冲突的时候,直接执行插入操作. 这种情况下,有三种方式执 ...
- 【漏洞复现】PHPCMS wap模块 SQL注入(附EXP)
漏洞影响版本:v9.5.8.v9.6.0 Step1: 访问:http://www.xxx.com/index.php?m=wap&a=index&siteid=1, 获取返回的coo ...