裸题,没什么好说的

第一个中国剩余定理

写暴力都过了。。可见这题有多水

代码:

#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 ):中国剩余定理裸题的更多相关文章

  1. POJ1006——Biorhythms(中国剩余定理)

    Biorhythms Description人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这天,人会在相应的方面表现出色. ...

  2. HDU 3579 Hello Kiki 中国剩余定理(合并方程

    题意: 给定方程 res % 14 = 5 res % 57 = 56 求res 中国剩余定理裸题 #include<stdio.h> #include<string.h> # ...

  3. poj1006 中国剩余定理&&中国剩余定理解析

    poj 1006 题的思路不是很难的,可以转化数学式: 现设 num 是下一个相同日子距离开始的天数 p,e,i,d 如题中所设! 那么就可以得到三个式子:( num + d ) % 23 == p: ...

  4. Biorhythms(中国剩余定理)

    http://shuxueshi.jie.blog.163.com/blog/static/13611628820104179856631/ 这篇博客写的很棒! #include<stdio.h ...

  5. 【题解】UVA756 Biorhythms (中国剩余定理)

    UVA756:https://www.luogu.org/problemnew/show/UVA756 思路 几乎是裸的中国剩余定理模板题 但是需要注意的是此题并不是求最小正整数解 而是求大于d的解 ...

  6. 51nod1079(中国剩余定理)

    题目链接: http://www.51nod.com/onlineJudge/user.html#!userId=21687 题意: 中文题诶~ 思路: 本题就是个中国剩余定理模板题,不过模拟也可以过 ...

  7. 【中国剩余定理】 poj 1006

    生理周期  简单模拟 对于超出23 * 28 * 33(21252)时进行求余运算即可. #include<stdio.h> int main() { //freopen("in ...

  8. 51nod1079 poj2891 中国剩余定理与其扩展

    题目链接:http://www.51nod.com/Challenge/Problem.html#!#problemId=1079 一个正整数K,给出K Mod 一些质数的结果,求符合条件的最小的K. ...

  9. [poj 2891] Strange Way to Express Integers 解题报告(excrt扩展中国剩余定理)

    题目链接:http://poj.org/problem?id=2891 题目大意: 求解同余方程组,不保证模数互质 题解: 扩展中国剩余定理板子题 #include<algorithm> ...

随机推荐

  1. Java学习笔记(1)——基本数据类型

    一.进制转换 10^n被称为权  10称为基数   计算机中正数和负数的关系是取反加一, 如: ~3+1=-3 补码边界运算有溢出风险 32位二进制补码最多表示2^32个数, -2G~2G 1,计算机 ...

  2. Python Cookbook笔记

    字符串:s.strip()  删除字符串开始和结尾的空白字符. s.lstrip() 删除左边的,s.rstrip()  删除右边的. 随机数:random.random()  生成0-1之间的数. ...

  3. java 截取字符串 拆分字符串

    例如 想要吧"90_python" 分成“90” 和“python” 从网上看到的方法: public class splitTest { public static void m ...

  4. Android源代码之Gallery专题研究(2)

    引言 上一篇文章已经解说了数据载入过程,接下来我们来看一看数据载入后的处理过程.依照正常的思维逻辑.当数据载入之后,接下来就应该考虑数据的显示逻辑. MVC显示逻辑 大家可能对J2EE的MVC架构比較 ...

  5. android Settings 解析

    1.Settings的主界面的实现: Settings采用了PreferenceActivity和PreferenceFragment结合的实现方式. Settings.java继承自Preferen ...

  6. [RxJS] Observables can throw errors

    Whenever we are writing code, we need to remember that things may go wrong. If an error happens in a ...

  7. HID Keyboard & Mouse descriptor.

    在USB中,USB HOST是通过各种描述符来识别设备的,有设备描述符,配置描述符,接口描述符,端点描述符,字符串描述符,报告描述符等等.USB报告描述符(Report Descriptor)是HID ...

  8. linux file命令

    1. file 是检测文件类型的命令.2. 文件类型就文件组织的方式,通常不同的文件类型执行不同的标准.例如我们熟知的:txt , doc , xls , pdf ...3. file 命令的简单用法 ...

  9. ComboBox( 下拉列表框)

    一. 加载方式//class 加载方式<select id="box" class="easyui-combobox" name="box&qu ...

  10. js中this的指向

    在js中this的指向对于新手来说一定是个难题,但是如果你真正理解了的话,也就没什么问题啦,下面就来讲讲this吧. JS中,this的值取决于调用的模式(调用对象),而JS中共有4种调用模式: 1. ...