裸题,没什么好说的

第一个中国剩余定理

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

代码:

#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. js点击按钮,放大对应图片代码

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. DedeCMS官方手册

    DedeCMSV5.3使用手册 DedeCMSV57数据库结构文档 Dedecms 文件目录结构

  3. SUBTOTAL 函数与所在行

    SUBTOTAL 函数与所在行 设计要点:数据汇总.隐藏.筛选 阿金:给你推荐一个函数SUBTOTAL. 秀秀:又是函数!俺不喜欢. 阿金:虽然你不喜欢函数,但是你也离不了啊,比如汇总. 秀秀:那倒是 ...

  4. muduo源代码分析--我对muduo的理解

    分为几个模块 EventLoop.TcpServer.Acceptor.TcpConnection.Channel等 对于EventLoop来说: 他仅仅关注里面的主驱动力,EventLoop中仅仅关 ...

  5. 输入内容, 列出可选的项: QComboBox

    #include "widget.h" #include "ui_widget.h" #include <QtGui/QCompleter> #in ...

  6. iOS 数据持久化

    一.plist文件存储 获得文件 NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDom ...

  7. Collection使用方法

    package cn.stat.p3.conection.demo; import java.util.ArrayList; import java.util.Collection; import j ...

  8. OpenCV——识别手写体数字

    这个是树莓派上运行的, opencv3 opencv提供了一张手写数字图片给我们,如下图所示,可以作为识别手写数字的样本库. 0到9共十个数字,每个数字有五行,一行100个数字.首先要把这5000个数 ...

  9. hdu5398 GCD Tree(lct)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud GCD Tree Time Limit: 5000/2500 MS (Java/O ...

  10. 自定义 Preference Header 布局

    1. Preference Header 概述: 对于什么是 Preference Header,以及何时使用 Preference Header,请参考我的另一篇博文: 何时使用 Preferenc ...