中国剩余定理……、

链接http://acm.hdu.edu.cn/showproblem.php?pid=1370

 /*************************************************************************
> File Name: xh.cpp
> Author: XINHUA
> Mail: 525799145@qq.com
> Created Time: 2013/7/11 星期四 17:46:00 新华
************************************************************************/ #include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
using namespace std;
int extend_gcd(int a,int b,int &x,int &y)
{
int m;
if(b==)
{
x=;y=;
return a;
}
else
{
m=extend_gcd(b,a%b,x,y);
int c=x;
x=y;
y=c-a/b*(y);
}
return m;
}
int mod(int a,int m)
{
int x,y,gcd;
gcd=extend_gcd(a,m,x,y);
if(gcd==)
{
if(x<)
x=(x%m+m)%m;
return x;
}
else return ;
}
int china(int m0[],int b[],int d)
{
int x,y,n,m=,a=-d;
int i;
for(i=;i<;i++) m*=m0[i];
for(i=;i<;i++)
{
n=m/m0[i];
extend_gcd(n,m0[i],x,y);
a=a+n*b[i]*x;
}
return a%m;
}
int main()
{
int p,e,i,d,k,sum,l=,m[]={
,,
},b[];
char c;
cin>>c;
while(cin>>p>>e>>i>>d)
{
if(p==-&&e==-&&i==-&&d==-)
break;
b[]=p;b[]=e;b[]=i;
sum=china(m,b,d);
if(sum<=) sum+=;
printf("Case %d: the next triple peak occurs in %d days.\n",++l,sum);
}
return ;
}

hdu 1370 Biorhythms的更多相关文章

  1. 【中国剩余定理】POJ 1006 & HDU 1370 Biorhythms

    题目链接: http://poj.org/problem?id=1006 http://acm.hdu.edu.cn/showproblem.php?pid=1370 题目大意: (X+d)%23=a ...

  2. Biorhythms HDU - 1370 (中国剩余定理)

    孙子定理: 当前存在三个式子,t%3=2,t%5=3,t%7=2.然后让你求出t的值的一个通解. 具体过程:选取3和5的一个公倍数t1能够使得这个公倍数t1%7==1,然后选取3和7的一个公倍数t2使 ...

  3. hdu 1370 Biorthythms 中国剩余定理

    Biorhythms Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  4. hdu 1370 || poj 1006 简单的中国剩余定理或者暴力

    Biorhythms Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Probl ...

  5. SQL递归方式实现省市区县级别查询

    数据库脚本 CREATE TABLE [dbo].[Std_Area]( [Id] [int] NOT NULL, [Name] [nvarchar](50) NULL, [ParentId] [in ...

  6. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  7. hdu 1573 X问题 (非互质的中国剩余定理)

    X问题 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  8. [转] HDU 题目分类

    转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008 ...

  9. HDU ACM 题目分类

    模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...

随机推荐

  1. iOS开发零基础教程之生成git所需的SSH keys

    在我们github看到了一个不错的第三方库时,可能我们想把他git clone到本地,我们需要复制他的SSH URL,如下图: 复制完地址之后,我们需要打开终端,然后输入命令: git clone + ...

  2. ADO.NET笔记——基本概念

    ADO.NET中的主要对象: Connection:连接对象.用于建立从应用程序到数据库服务器指定数据库的连接通道 Command:命令对象.用于执行增删查改等数据库语句命令 DataReader:数 ...

  3. 安装gitolite,并ssh公钥无密码登录

    安装gitolite,并ssh公钥无密码登录 gitolite是管理git版本库的一种方案,它将git版本库的管理信息放在了一个特殊git版本库里.gitolite与linux操作系统集成了,需要使用 ...

  4. 分享:JS比较两个日期大小

    发布:thatboy   来源:Net     [大 中 小] 本文介绍下,在javascript代码中,比较两个日期大小的方法,有需要的朋友参考下. 转自:http://www.jbxue.com/ ...

  5. mysql rand随机查询记录效率

    一直以为mysql随机查询几条数据,就用 SELECT * FROM `table` ORDER BY RAND() LIMIT 5 就可以了. 但是真正测试一下才发现这样效率非常低.一个15万余条的 ...

  6. Crusher Django Tutorial(5) 使用内置管理员系统

    http://crusher-milling.blogspot.com/2013/09/crusher-django-tutorial5-using-admin.html 顺便学习一下FQ Crush ...

  7. 植物大战僵尸中文第二版和年度版 游戏分析及delphi源码

    00413184 |. E8 77E30100   |CALL PlantsVs.00431500                  ; 地上的物品00413189 |. 8D7424 10     ...

  8. Selenium-RC Python 2.7 环境配置

    1.下载并安装Python http://www.python.org/getit/,我使用的是2.7.3的python版本 2.下载并安装setuptools[这个工具是python的基础包工具] ...

  9. 1093. Count PAT's (25)

    The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and ...

  10. java之jar命令详解

    1. JAR 文件包 JAR 文件就是 Java Archive File,顾名思意,它的应用是与 Java 息息相关的,是 Java 的一种文档格式.JAR 文件非常类似 ZIP 文件——准确的说, ...