POJ 1006 Biorhythms --中国剩余定理(互质的)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 103539 | Accepted: 32012 |
Description
Since the three cycles have different periods, the peaks of the three cycles generally occur at different times. We would like to determine when a triple peak occurs (the peaks of all three cycles occur in the same day) for any person. For each cycle, you will be given the number of days from the beginning of the current year at which one of its peaks (not necessarily the first) occurs. You will also be given a date expressed as the number of days from the beginning of the current year. You task is to determine the number of days from the given date to the next triple peak. The given date is not counted. For example, if the given date is 10 and the next triple peak occurs on day 12, the answer is 2, not 3. If a triple peak occurs on the given date, you should give the number of days to the next occurrence of a triple peak.
Input
Output
Case 1: the next triple peak occurs in 1234 days.
Use the plural form ``days'' even if the answer is 1.
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.
Source
- /*
- 纯中国剩余定理。
- */
- #include<iostream>
- #include<cstdio>
- #include<cstdlib>
- #include<cstring>
- using namespace std;
- __int64 a[];
- __int64 m[]={,,,};
- __int64 tom;
- __int64 Ex_gcd(__int64 a,__int64 b,__int64 &x,__int64 &y)
- {
- if(b==)
- {
- x=;
- y=;
- return a;
- }
- __int64 g=Ex_gcd(b,a%b,x,y);
- __int64 hxl=x-(a/b)*y;
- x=y;
- y=hxl;
- return g;
- }
- __int64 china()
- {
- __int64 i,x,y,mi,hxl=,sum=,d;
- for(i=;i<=;i++)
- sum=sum*m[i];
- for(i=;i<=;i++)
- {
- mi=sum/m[i];
- d=Ex_gcd(m[i],mi,x,y);
- hxl=(hxl+mi*y*a[i])%sum;
- }
- hxl=hxl-tom;
- if(hxl>)
- return hxl;
- else
- return hxl+;
- }
- void make_ini(__int64 t)
- {
- __int64 k;
- k=china();
- printf("Case %I64d: the next triple peak occurs in %I64d days.\n",t++,k);
- }
- int main()
- {
- __int64 sb,p,e,i,t=;
- // scanf("%I64d",&sb);
- while(scanf("%I64d%I64d%I64d%I64d",&p,&e,&i,&tom)>)
- {
- if(p==- && e==- && i==- &&tom==-)break;
- a[]=p;a[]=e;a[]=i;
- make_ini(++t);
- }
- 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 ...
- PKU POJ 1006 Biorhythms (中国剩余定理)
中国剩余定理 x = ai (mod mi) ai和mi是一组数,mi两两互质,求x 令Mi = m1*m2*~mk 其中,mi不包含在内. 因为mi两两互质,所以存在x和y, st M ...
- 模板-->中国剩余定理[互质版本]
如果有相应的OJ题目,欢迎同学们提供相应的链接 相关链接 所有模板的快速链接 扩展欧几里得extend_gcd模板 poj_1006_Biorhythms,my_ac_code 简单的测试 None ...
- POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理)
POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理) 题意分析 不妨设日期为x,根据题意可以列出日期上的方程: 化简可得: 根据中国剩余定理求解即可. 代码总览 #include & ...
- Biorhythms(中国剩余定理)
http://shuxueshi.jie.blog.163.com/blog/static/13611628820104179856631/ 这篇博客写的很棒! #include<stdio.h ...
- POJ 1006 Biorhythms (中国剩余定理)
在POJ上有译文(原文右上角),选择语言:简体中文 求解同余方程组:x=ai(mod mi) i=1~r, m1,m2,...,mr互质利用中国剩余定理令M=m1*m2*...*mr,Mi=M/mi因 ...
- poj 1006 Biorhythms (中国剩余定理模板)
http://poj.org/problem?id=1006 题目大意: 人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这 ...
- poj 1006:Biorhythms(水题,经典题,中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 110991 Accepted: 34541 Des ...
随机推荐
- 替代iframe新逻辑
使用ajax请求.下面是代码逻辑 $.ajax({ url:url, type:'get', dataType: "text", success:function(msg){ $( ...
- WebStorm 简单部署服务器进行测试操作
WebStorm 简单部署服务器对外发布接口 第一步: 查看webstorm防火墙是否允许链接,控制面板-->防火墙-->高级设置 入站规则-->webstrom是否允许链接 ,双击 ...
- JDK下载与安装、 Eclipse下载与使用的总结心得_20173311118_牛明旺
一.JDK下载与安装心得: ① 从官网http://www.oracl.com/technetwork/java上下载JDK,注意一定要同意该网站上的协议,否则下载不了(即点击“Accept Lic ...
- (Lua) C++ 加入 Lua 環境擴充應用強度
Lua 在網上有非常多的介紹,就是一個小而巧的語言,可以放入嵌入式系統 也可以在一般的應用上非常強大,這邊主要記錄如何讓Lua加入C++裡頭應用 Lua source code 是以 C 語言下去編寫 ...
- MySQL数据库的账户管理
账户管理 在生产环境下操作数据库时,绝对不可以使用root账户连接,而是创建特定的账户,授予这个账户特定的操作权限,然后连接进行操作,主要的操作就是数据的crud MySQL账户体系:根据账户所具有的 ...
- Django 登陆注册实现
路由层 from django.conf.urls import url from django.contrib import admin from app01 import views urlpat ...
- 求幂大法,矩阵快速幂,快速幂模板题--hdu4549
hdu-4549 求幂大法.矩阵快速幂.快速幂 题目 M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 ...
- Service层异常处理
1.在service方法里面如果对异常进行了捕获的话,该事务是不会进行回滚的 * 默认spring事务只在发生未被捕获的 runtime excetpion()时才回滚. * * spring aop ...
- Visual Studio 跨平台開發實戰(3) - Xamarin iOS 多頁面應用程式開發 (转帖)
前言 在前一篇教學中, 我們學會如何使用Visual Studio 搭配Xcode 進行iOS基本控制項的操作. 但都是屬於單一畫面的應用程式. 這次我們要來練習如何透過Navigation Cont ...
- (转) Linux 内核运行参数修改——sysctl命令
原文:https://blog.csdn.net/u012707739/article/details/78254241 sysctl命令被用于在内核运行时动态地修改内核的运行参数,可用的内核参数在目 ...