HDU 1370 Biorhythms
来源:互联网 发布:红蜘蛛软件破解网络 编辑:程序博客网 时间:2024/06/06 09:27
题意为:人有三个生理周期顶峰时间为p,e,i,而这三个生理周期会分别在23、28、33后再次达到顶峰。已知这一次达到顶峰的时间为d,求下一次达到顶峰的时间。
根据分析题意我们会发现待求时间t%23=p,t%28=e,t%33=i,且这个t大于d,这就转换成一个中国剩余定理的模型了即上图左。这是我们可以根据上图右的算法逐步进行计算。最后注意判断x与d的大小,若小,就加上三者的最小公倍数,正好这三个数字互质,即为三者乘积。
下附AC代码。
#include<stdio.h>#define maxn 5#define mod 21252using namespace std;void exgcd(int a,int b,int &x,int &y){ if(b==0) { x=1; y=0; return ; } exgcd(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=1;int now;int x,y;int ans=0;for(int i=0;i<n;i++)m*=a[i];for(int i=0;i<n;i++){now=m/a[i];exgcd(now,a[i],x,y);ans+=x*now*b[i];}return ans%m;}int a[maxn]={23,28,33};int b[maxn];int main(){int kase=0;int d;scanf("%d",&d);while(~scanf("%d%d%d%d",&b[0],&b[1],&b[2],&d) && d!=-1){kase++;int ans=crt(a,b,3)-d;if(ans<=0)ans+=mod;printf("Case %d: the next triple peak occurs in %d days.\n",kase,ans);}}
阅读全文
0 0
- HDU 1370 Biorhythms
- 【HDU】 1370 Biorhythms
- HDU 1370 Biorhythms
- HDU 1370 Biorhythms
- ACM 数论 hdu 1370 Biorhythms
- Biorhythms HDU
- POJ 1006 && HDU 1370 Biorhythms(水~)
- HDU 1370 Biorhythms (中国剩余定理)
- hdu 1370 Biorhythms(中国剩余定理)
- HDU 1370 Biorhythms 中国剩余定理
- 【中国剩余定理】POJ 1006 & HDU 1370 Biorhythms
- HDU 1370 Biorhythms(中国剩余定理 + 拓展欧几里得)
- HDU 1370 Biorhythms (中国剩余定理, 简单套用)
- 中国剩余定理 Biorhythms HDU
- hdoj-1370-Biorhythms
- Biorhythms
- Biorhythms
- Biorhythms
- mybatis maven generator 插件自动生成代码
- AndroidUI——HorizontalListView实现水平滑动
- leetcode 101. Symmetric(对称的) Tree
- 数组(array)应用
- 词频统计(一):C++使用Vector做词频统计
- HDU 1370 Biorhythms
- JavaScript数组的常用方法
- TCP/IP协议简介
- Jdk
- Android基础总结(一)
- PHP依赖管理工具Composer配置安装及基本使用
- what is SVM?
- Android中的Builder模式
- 百练 1321: 棋盘问题