poj 1006 Biorhythms(中國剩餘定理)
自己的題解略混亂(再看自己都沒看懂)所以還是貼一個神犇的講解(十分簡單易懂)
題目大意:
人有三個生理週期,給出三個週期的初始日期,請求出多少天后三個生理週期同時出現。
體力週期–23天
感情週期–28天
智力週期–33天
首先解釋中國剩餘定理這個神奇的東西 >o<
先來一個典型例題—-偉大的韓信點兵創造了這道題目 >o<
韓信點兵,三三餘二,五五餘三,七七餘二。
設共有n個人(n為符合條件的最小數)
n%3=2;
n%5=3;
n%7=2;
首先求滿足n%3=2的數
設a%3=1
於是a=4
易證a*2%3=2,so a*2=x;
所以
3*5*x%7=1
a=3*5*x
5*7*y%3=1
3*7*z%5=1
b c同上
so n=(a*7+b*3+c*5)%lcm(3,7,5)
此題同理
求(n+d)%23=p;
(n+d)%28=e;
(n+d)%33=i;
求n
#include<iostream>// 中國剩餘定理
#include<cstdio>
using namespace std;//p--體力週期23;e--感情週期28;i--智力週期33;
int main(){
int p,e,i,d,cnt=0;
//23*28*2=1288
//23*33*19=14421
//28*33*6=5544
while(scanf("%d%d%d%d",&p,&e,&i,&d)){
if(p==-1&&e==-1&&i==-1 &&d==-1)
break;
cnt++;
int ans;
ans=((1288*i+14421*e+5544*p)+21252-d)%(23*28*33);//因為可能出現負數,所以要加上21252
if(ans==0)
ans=21252;
cout<<"Case "<<cnt<<": the next triple peak occurs in "<<ans<<" days."<<endl;
}
return 0;
}
相關推薦
poj 1006 Biorhythms(中國剩餘定理)
自己的題解略混亂(再看自己都沒看懂)所以還是貼一個神犇的講解(十分簡單易懂) 題目大意: 人有三個生理週期,給出三個週期的初始日期,請求出多少天后三個生理週期同時出現。 體力週期–23天 感情週
Poj 1006 Biorhythms 中國剩餘定理
Description 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 phys
POJ 1006 ——Biorhythms 中國剩餘定理模板
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 112928 Accepted: 35337 Description Some people believe that there are th
【POJ 1006】【CRT(中國剩餘定理)模板題】Biorhythms
描述: Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 130935 Accepted: 41750 Description Some people believe
POJ-1006-Biorhythms(中國剩餘定理)
Biorhythms Description Some people believe that there are three cycles in a person's life that start the day he or she is born. These
poj 1006 Biorhythms(中國剩餘定理)
題意: x === p ( mod 23 ) x === e ( mod 28 ) x === i ( mod 33 ) 給p e i ,求x 。 解析: 23 28 33互素,所以用中國剩餘定理做。 用之前的解同餘方程組的方法也試了試,很噁心,樣例裡面有0 0 0 0
POJ 1006 Biorhythms (中國剩餘定理)
大意:有中文翻譯 思路:中國剩餘定理的完美詮釋 中國剩餘定理介紹 在《孫子算經》中有這樣一個問題:“今有物不知其數,三三數之剩二(除以3餘2),五五數之剩三(除以5餘3),七七數之剩二(除以7餘2),問物幾何?”這個問題稱為“孫子問題”,該問題的一般解法國際上稱
POJ 1006:Biorhythms 中國剩餘定理
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 121194 Accepted: 38157 Description Some people believe that
POJ 1006 Biorhythms | 中國剩余定理
同時 include net day 要求 names amp -s string 題目: 人自出生起就有體力,情感和智力三個生理周期,分別為23,28和33天。一個周期內有一天為峰值,在這一天,人在對應的方面(體力,情感或智力)表現最好。 通常這三個周期的峰值不會是同一天
【文文殿下】【CF724C】Ray Tracing (中國剩餘定理)
題解 我們考慮將棋盤擴大一倍,這樣相當於取膜。然後,我們只要對x,y,的位置分類討論,做四次crt就行。具體細節看文文程式碼。 #include<cstdio> #include<algorithm> typedef long long ll; const ll inf = 100
Strange Way to Express Integers(不互素的的中國剩餘定理)
F - Strange Way to Express Integers Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%I64d & %I64u SubmitStatus
韓信點兵(中國剩餘定理)
孫子算經中有記載:“今有數不知其數:二三數之餘而,五五之數餘三,七七數之餘而,問物幾何?”它的意思就是有一些物品,如果3個3個數 剩兩個,如果5個5個數,最後剩3個,如果7個個7個數,最後剩2個,求這
hdu1006Biorhythms(中國剩餘定理)
Description 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
模線性方程組(中國剩餘定理)
《孫子算經》裡有這樣一個問題,“今有物不知其數,三三數之剩二(除以3餘2),五五數之剩三(除以5餘3),七七數之剩二(除以7餘2),問物幾何?”,解決這個問題的方法稱為中國剩餘定理,也叫孫子定理。中國古代還有一個叫做“韓信點兵”的問題,和這個問題本質是一樣的。 很明顯這個物
【Codeforces2015ICL,Finals,Div. 1#J】Ceizenpok's formula(擴充套件Lucas定理+中國剩餘定理)
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> usin
poj1006 生理週期(中國剩餘定理)
生理週期 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 122157 Accepted: 38518 Description 人生來就有三個生理週期,分別為體力、感情和智力週期,它們的週期長度為
poj 1006 Biorhythms(中國剩餘定理的應用)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 125633 Accepted: 39673 Description Some people believe that
Biorhythms POJ - 1006 (中國剩餘定理)
傳送門 題意:已知一個人的身體,智力和情感的迴圈週期,然後給出一個人身體,智力和情感的開始值,最後再給出一個固定時間,問在下一次三個共同達到峰值的時間在這個固定時間多長時間後。 題解:中國剩餘定理板題,首先得了解拓展gcd,知道了這個後,再瞭解下求逆元傳送門,在看下百科上的解釋就懂了傳送門,
【中國剩餘定理】POJ Biorhythms 1006
You will be given a number of 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 o
中國剩余定理算法詳解 + POJ 1006 Biorhythms 生理周期
ace printf urn str cst 算法 .com += scan 轉載請註明出處:http://exp-blog.com/2018/06/24/pid-1054/ 1 #include <iostream> 2 #include <cst