poj1006 ( hdu1370 ):中国剩余定理裸题
裸题,没什么好说的
第一个中国剩余定理
写暴力都过了。。可见这题有多水
代码:
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
#define MAX 200000000
#define ull unsigned long long
const int MAXN = ;
int a[];
int m[]={,,};
int exgcd(int a,int b,int &x,int &y)
{
if(b==)
{
x=;y=;
return a;
}
int r=exgcd(b,a%b,x,y);
int t=x;
x=y;
y=(t-a/b*y);
return r;
}
int china(int n)
{
int M=;
int ans=;
int x,y,d;
for(int i=;i<n;i++)
{
M*=m[i];
}
for(int i=;i<n;i++)
{
int mi=M/m[i];
int x,y;
d=exgcd(mi,m[i],x,y);
ans=(ans+a[i]*mi*x)%M;
}
while(ans<)
ans+=M;
return ans;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
getchar();
int p,e,d,n,x,f;
int tt=;
int ans=;
while(scanf("%d%d%d%d",&a[],&a[],&a[],&d)&&(a[]!=-||a[]!=-||a[]!=-||d!=-))
{
tt++;
ans=china();
while(ans<=d)
ans+=;
printf("Case %d: the next triple peak occurs in %d days.\n",tt,ans-d);
}
while(t)
printf("\n");
}
return ;
}
poj1006 ( hdu1370 ):中国剩余定理裸题的更多相关文章
- POJ1006——Biorhythms(中国剩余定理)
Biorhythms Description人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这天,人会在相应的方面表现出色. ...
- HDU 3579 Hello Kiki 中国剩余定理(合并方程
题意: 给定方程 res % 14 = 5 res % 57 = 56 求res 中国剩余定理裸题 #include<stdio.h> #include<string.h> # ...
- poj1006 中国剩余定理&&中国剩余定理解析
poj 1006 题的思路不是很难的,可以转化数学式: 现设 num 是下一个相同日子距离开始的天数 p,e,i,d 如题中所设! 那么就可以得到三个式子:( num + d ) % 23 == p: ...
- Biorhythms(中国剩余定理)
http://shuxueshi.jie.blog.163.com/blog/static/13611628820104179856631/ 这篇博客写的很棒! #include<stdio.h ...
- 【题解】UVA756 Biorhythms (中国剩余定理)
UVA756:https://www.luogu.org/problemnew/show/UVA756 思路 几乎是裸的中国剩余定理模板题 但是需要注意的是此题并不是求最小正整数解 而是求大于d的解 ...
- 51nod1079(中国剩余定理)
题目链接: http://www.51nod.com/onlineJudge/user.html#!userId=21687 题意: 中文题诶~ 思路: 本题就是个中国剩余定理模板题,不过模拟也可以过 ...
- 【中国剩余定理】 poj 1006
生理周期 简单模拟 对于超出23 * 28 * 33(21252)时进行求余运算即可. #include<stdio.h> int main() { //freopen("in ...
- 51nod1079 poj2891 中国剩余定理与其扩展
题目链接:http://www.51nod.com/Challenge/Problem.html#!#problemId=1079 一个正整数K,给出K Mod 一些质数的结果,求符合条件的最小的K. ...
- [poj 2891] Strange Way to Express Integers 解题报告(excrt扩展中国剩余定理)
题目链接:http://poj.org/problem?id=2891 题目大意: 求解同余方程组,不保证模数互质 题解: 扩展中国剩余定理板子题 #include<algorithm> ...
随机推荐
- chomp方法
chomp方法属于String类里面的: "hello".chomp #=> "hello" "hello\n".chomp #=&g ...
- JS(六)
没有视频看了,心里有点慌啊,像这种每天都会灌输很多知识的学习方式,我觉得提前预习真的是有奇效,不然不容易跟上老师的思维. 1.发送验证码:简单 <!DOCTYPE html> <ht ...
- npm包管理工具
# 从官方包仓库中查找forever包的信息 npm search forever # 查看forever包中package.json的信息 npm view forever # 下载,安装forev ...
- iOS 捕获系统外异常
iOS 捕获系统外异常 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:太 ...
- [Javascript] Safe Nested Object Inspection
A common problem when dealing with some kinds of data is that not every object has the same nested s ...
- Tabs( 选项卡)
一. 加载方式 //class 加载方式<div id="box" class="easyui-tabs" style="width:500px ...
- SQL数据库增删改查基本语句
adoquery1.Fielddefs[1].Name; 字段名dbgrid1.columns[0].width:=10; dbgrid的字段宽度adoquery1.Fields[i].DataTyp ...
- 路由器密码破解工具 Hydra 7.5
之前只在 Browser 中保存了路由管理密码,无奈升级时管理的密码丢失了,又不想重新设置,所以尝试破解登录密码. 使用破解工具 Hydra 7.5. # hydra -l username -x : ...
- SQL2008安装重启失败
我今天安装SQL2008的一些问题经历SQL2008安装重启失败大致出错信息如下:RebootRequiredCheck 检查是否需要挂起计算机重新启动.挂起重新启动会导致安装程序失败. 失败 需要重 ...
- Jquery 使用JSOPN实例
1.说明 dataType:返回的数据类型 jsonp:传递给请求处理程序或页面的,用以获得jsonp回调函数名的参数名(一般默认为:callback) jsonpCallback:自定义的jsonp ...