POJ 1006 Biorhythms
来源:互联网 发布:九分裤牌子知乎 编辑:程序博客网 时间:2024/06/04 18:51
题意:
给你p, e, i分别表示体力、情感和智力高峰出现的时间和它们的周期长度分别是23天、28天和33天,问你下一次三个都出现高峰的日期是多少,结果模21252。
思路:
假设那天为T,则有如下公式:
T%23=p
T%28=e
T%33=I
得出三个同余方程组,自然想到用中国余定理。
#include<cstdio>using namespace std;int Extended_Euclid(int a,int b,int &x,int &y){int d;if(b==0){x=1;y=0;return a;}d=Extended_Euclid(b,a%b,y,x);y-=a/b*x;return d;}int Chinese_Remainder(int a[],int w[],int len){int i,d,x,y,m,n,ret;ret=0;n=1;for (i=0;i<len;i++) n*=w[i];for (i=0;i<len;i++){m=n/w[i];d=Extended_Euclid(w[i],m,x,y);ret=(ret+y*m*a[i])%n;}return (n+ret%n)%n;}int main(){int a[5],w[5]={23,28,33},d,cas=1;while(1){for(int i=0;i<3;i++){scanf("%d",&a[i]);a[i]%=w[i];}scanf("%d",&d);if(d==-1) break;int ans=(Chinese_Remainder(a,w,3)-d+21252)%21252;if(!ans) ans=21252;printf("Case %d: the next triple peak occurs in %d days.\n",cas++,ans);}return 0;}
0 0
- poj 1006 Biorhythms
- poj 1006 Biorhythms
- poj 1006 Biorhythms
- POJ 1006 Biorhythms
- POJ 1006 Biorhythms
- POJ 1006 Biorhythms
- 【POJ】1006 Biorhythms
- POJ-1006:Biorhythms
- POJ 1006 Biorhythms
- POJ 1006 Biorhythms
- POJ 1006 Biorhythms
- poj 1006 Biorhythms
- POJ 1006 Biorhythms
- Poj 1006 Biorhythms
- POJ 1006 Biorhythms
- poj 1006 hdu1370 Biorhythms
- 【POJ】1006 Biorhythms
- poj 1006 Biorhythms
- scala基础24-偏函数初探
- Android:学习AIDL,这一篇文章就够了(上)
- 容联?融云?环信?开发者怎么选
- Python爬虫学习系列教程-----------爬虫系列 你值的收藏
- B. Lovely Palindromes
- POJ 1006 Biorhythms
- 贝塞尔曲线开发的艺术
- maven启动
- day07_configparser
- 为什么不习惯使用qml?
- Flask测试跨域请求
- 不同的子序列(leetcode hard)动态规划
- Android存储系统之架构篇
- Android数据库相关