POJ 1006 Biorhythms(中国剩余定理)
题目地址:POJ 1006
学习了下中国剩余定理。參考的该博客。博客戳这里。
中国剩余定理的求解方法:
假如说x%c1=m1,x%c2=m2,x%c3=m3.那么能够设三个数R1,R2,R3.R1为c2,c3的公倍数且余c1为1,同理。R2,R3也是如此。然后设z=R1*m1+R2*m2+R3*m3,那么z就是当中一个解。并且每隔(c1,c2,c3)的最小公倍数就是一个解。想要最小解的话,仅仅需对最小公倍数取余即可了。
以下的代码未删改。比赛的时候为了避免超时,R1,R2,R3的求解过程全然没有必要放在程序里,自己算出来直接用上即可。
代码例如以下:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm> using namespace std;
#define LL __int64
int main()
{
LL a, b, c, d, R1, R2, R3, i, j, k, R, num=0;
R1=28*33;
R2=23*33;
R3=23*28;
for(i=1;; i++)
{
if(R1*i%23==1)
{
R1*=i;
break;
}
}
for(i=1;; i++)
{
if(R2*i%28==1)
{
R2*=i;
break;
}
}
for(i=1;; i++)
{
if(R3*i%33==1)
{
R3*=i;
break;
}
}
while(scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&d)!=EOF)
{
if(a<0&&b<0&&c<0&&d<0)
break;
num++;
R=R1*a+R2*b+R3*c;
LL z, ans;
z=R%21252;//21252为a,b,c的最小公倍数
if(z<=d)
{
z+=21252;
}
ans=z-d;
printf("Case %I64d: the next triple peak occurs in %I64d days.\n",num,ans);
}
return 0;
}
POJ 1006 Biorhythms(中国剩余定理)的更多相关文章
- POJ 1006 - Biorhythms (中国剩余定理)
B - Biorhythms Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Subm ...
- 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 & ...
- Biorhythms(中国剩余定理)
http://shuxueshi.jie.blog.163.com/blog/static/13611628820104179856631/ 这篇博客写的很棒! #include<stdio.h ...
- 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 ...
- POJ 1006 Biorhythms (中国剩余定理)
在POJ上有译文(原文右上角),选择语言:简体中文 求解同余方程组:x=ai(mod mi) i=1~r, m1,m2,...,mr互质利用中国剩余定理令M=m1*m2*...*mr,Mi=M/mi因 ...
- 中国剩余定理 POJ 1006 Biorhythms
题目传送门 题意:POJ有中文题面 分析:其实就是求一次同余方程组:(n+d)=p(%23), (n+d)=e(%28), (n+d)=i(%33),套用中国剩余定理模板 代码: /********* ...
随机推荐
- POJ 3414 Pots bfs打印方案
题目: http://poj.org/problem?id=3414 很好玩的一个题.关键是又16ms 1A了,没有debug的日子才是好日子.. #include <stdio.h> # ...
- iOS 静态库中使用宏定义区分iPhone模拟器与真机---备用
问题描述 一般项目中,可以使用宏定义来判断模拟器还是真机,这无疑是有效的. #if TARGET_IPHONE_SIMULATOR #define SIMULATOR 1 #elif TARGET_O ...
- 意犹未尽而来的第一篇Android 逆向
游戏:咕噜王国大冒险 平台:android 目标: 1. 去除乱七八糟提示(本篇目标) 2. 去除google弹窗 3. 破解“all stages” 破文开始: 1. 使用APKIDE反编译:搜索字 ...
- Linq Distinct List 去重复
//调用 return producePlantlst.Distinct(new item_collection_DistinctBy_item1()).ToList(); //方法 public c ...
- [转贴]xcode帮助文档
突然间得到了一台MAC ,这时候不学OC 更待何时学呀?马上找了IOS开发的书和网上的帖子看,最近在开源力量那里看了TINYFOOL的入门讲座,讲的都很虚,可能时间不够吧,也没看到什么例子呀,什么的, ...
- 【Xamarin挖墙脚系列:如何从一个Apk程序转化为Xamarin的程序】
原文:[Xamarin挖墙脚系列:如何从一个Apk程序转化为Xamarin的程序] 工欲善其事必先利其器:工具下载:http://pan.baidu.com/s/1skxjwgH 接下来,我用个小的应 ...
- paip.php eclipse output echo 乱码
paip.php eclipse output echo 乱码 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.c ...
- saxReader的列子
import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xml.sax.Attributes; import org.x ...
- Node v4.1.1
Installing Node.js via package manager curl --silent --location https://deb.nodesource.com/setup_4.x ...
- codeforce
A. Playing with Dice time limit per test 1 second memory limit per test 256 megabytes input standard ...