poj 1006 Biorhythms (中国剩余定理模板)
http://poj.org/problem?id=1006
题目大意:
人生来就有三个生理周期,分别为体力、感情和智力周期,它们的周期长度为23天、28天和33天。每一个周期中有一天是高峰。在高峰这天,人会在相应的方面表现出色。例如,智力周期的高峰,人会思维敏捷,精力容易高度集中。因为三个周期的周长不同,所以通常三个周期的高峰不会落在同一天。对于每个人,我们想知道何时三个高峰落在同一天。对于每个周期,我们会给出从当前年份的第一天开始,到出现高峰的天数(不一定是第一次高峰出现的时间)。你的任务是给定一个从当年第一天开始数的天数,输出从给定时间开始(不包括给定时间)下一次三个高峰落在同一天的时间(距给定时间的天数)。例如:给定时间为10,下次出现三个高峰同天的时间是12,则输出2(注意这里不是3)。
注意: 所求的时间小于21252。
根据题意可以得出公式:
(x + d)% 23 = p;
(x + d)% 28 = i;
(x + d)% 33 = e;
那么我们可以根据中国剩余定理求出x+d,就可以解题了
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<stdlib.h> using namespace std; typedef long long LL; void gcd(int a, int b, int &x, int &y)
{
if(b == )
{
x = ;
y = ;
return ;
}
gcd(b, a % b, x, y);
int k = x;
x = y;
y = k - a / b * y;
} int CRT(int a[], int b[], int n)
{
int M = , N, ans = , x, y;
for(int i = ; i < n ; i++)
M *= a[i];
for(int i = ; i < n ; i++)
{
N = M / a[i];
gcd(N, a[i], x, y);
ans += N * x * b[i];
}
return ans % M;
} int main()
{
int f = , d;
int a[] = {, , }, b[];
while()
{
f++;
for(int i = ; i < ; i++)
scanf("%d", &b[i]);
scanf("%d", &d);
if(d == -)
break;
int m = (CRT(a, b, ) - d) % ;
if(m <= )
m += ;
printf("Case %d: the next triple peak occurs in %d days.\n", f, m); }
return ;
}
poj 1006 Biorhythms (中国剩余定理模板)的更多相关文章
- POJ 1006 - Biorhythms (中国剩余定理)
B - Biorhythms Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Subm ...
- POJ 1006 Biorhythms(中国剩余定理)
题目地址:POJ 1006 学习了下中国剩余定理.參考的该博客.博客戳这里. 中国剩余定理的求解方法: 假如说x%c1=m1,x%c2=m2,x%c3=m3.那么能够设三个数R1,R2,R3.R1为c ...
- POJ 1006 Biorhythms --中国剩余定理(互质的)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 103539 Accepted: 32012 Des ...
- PKU POJ 1006 Biorhythms (中国剩余定理)
中国剩余定理 x = ai (mod mi) ai和mi是一组数,mi两两互质,求x 令Mi = m1*m2*~mk 其中,mi不包含在内. 因为mi两两互质,所以存在x和y, st M ...
- POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理)
POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理) 题意分析 不妨设日期为x,根据题意可以列出日期上的方程: 化简可得: 根据中国剩余定理求解即可. 代码总览 #include & ...
- 中国剩余定理 POJ 1006 Biorhythms
题目传送门 题意:POJ有中文题面 分析:其实就是求一次同余方程组:(n+d)=p(%23), (n+d)=e(%28), (n+d)=i(%33),套用中国剩余定理模板 代码: /********* ...
- Biorhythms(中国剩余定理)
http://shuxueshi.jie.blog.163.com/blog/static/13611628820104179856631/ 这篇博客写的很棒! #include<stdio.h ...
- poj 1006中国剩余定理模板
中国剩余定理(CRT)的表述如下 设正整数两两互素,则同余方程组 有整数解.并且在模下的解是唯一的,解为 其中,而为模的逆元. 模板: int crt(int a[],int m[],int n) { ...
- poj 1006:Biorhythms(水题,经典题,中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 110991 Accepted: 34541 Des ...
随机推荐
- [ML] Gradient Descend Algorithm [Octave code]
function [theta, J_history] = gradientDescentMulti(X, y, theta, alpha, num_iters) m = length(y); % n ...
- 简单的TCP代理服务器
我之前的一篇文章(http://www.cnblogs.com/MikeZhang/archive/2012/03/07/socketRedirect.html )中介绍过用python写的一个简单的 ...
- 关于phpmailer邮件发送
今天有个需求,要把phpmailer集成到框架里面 所以我去官方下载了 phpmail5.2.6 地址在 https://github.com/PHPMailer/PHPMailer/releases ...
- WPF 实现指定UI控件截图
using System.Windows.Media.Imaging; using System.IO; private void SaveToImage(FrameworkElement ui, s ...
- 「小程序JAVA实战」小程序的分享和下载功能(69)
转自:https://idig8.com/2018/09/25/xiaochengxujavashizhanxiaochengxudefenxianghexiazaigongneng68/ 在小程序上 ...
- Tutorial: Getting Started with Spring Security
This tutorial will cover a basic scenario where it integrates Spring Security, using database-backe ...
- 有单例模式 Singleton 涉及的一些防止类被继承的东西
c#中 : ------------------------------- 当对一个类应用 sealed 修饰符时,此修饰符会阻止其他类从该类继承. java中: ------------------ ...
- 【335】Install PyDev in Eclipse IDE
Reference: Eclipse和PyDev搭建完美Python开发环境(Windows篇) Reference: Install the PyDev plug-in for Eclipse Do ...
- 记一次 .net core publish 之后找不到视图文件的问题
周末将VS从15.3 升级到15.5 ,之后又将VS版本由社区版,升级为企业版. 于是问题来了: 项目publish 之后找不到视图文件了??? 问题很是蛋疼,后来仔细想了一下,也没有动什么东西.查看 ...
- LevelDb日知录之五:MemTable详解
[LevelDb日知录之五:MemTable详解] LevelDb日知录前述小节大致讲述了磁盘文件相关的重要静态结构,本小节讲述内存中的数据结构Memtable,Memtable在整个体系中的重要地位 ...