惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
J
Java Code Geeks
WordPress大学
WordPress大学
博客园 - 【当耐特】
博客园 - 叶小钗
小众软件
小众软件
博客园 - 聂微东
宝玉的分享
宝玉的分享
量子位
人人都是产品经理
人人都是产品经理
博客园_首页
罗磊的独立博客
腾讯CDC
美团技术团队
Google DeepMind News
Google DeepMind News
W
WeLiveSecurity
I
InfoQ
Engineering at Meta
Engineering at Meta
云风的 BLOG
云风的 BLOG
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Threat Research - Cisco Blogs
Google DeepMind News
Google DeepMind News
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hacker News: Front Page
B
Blog RSS Feed
L
LangChain Blog
C
Check Point Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
G
GRAHAM CLULEY
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Microsoft Azure Blog
Microsoft Azure Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
博客园 - Franky
S
Schneier on Security
Attack and Defense Labs
Attack and Defense Labs
Microsoft Security Blog
Microsoft Security Blog
N
Netflix TechBlog - Medium
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Tenable Blog
Simon Willison's Weblog
Simon Willison's Weblog
L
LINUX DO - 热门话题
阮一峰的网络日志
阮一峰的网络日志
Hacker News: Ask HN
Hacker News: Ask HN
A
Arctic Wolf
Schneier on Security
Schneier on Security
The Last Watchdog
The Last Watchdog
Latest news
Latest news
T
The Exploit Database - CXSecurity.com

博客园 - saintqdd

hdu 1102 pku 2421 解题报告 pku 2777 Count Color 解体报告 石子合并问题 nkoj1139和乘积最大那题一样. A Tour in Loquat Orchard (FZU 2007 ICPC Qualification Round I tzw) 最大黑区域 滑雪 一道经典题,humble number 今天碰到了一个很诡异的题,Alphacode (zoj 2202) 这两天经常碰到dp题,就写了一个0-1背包 实训以来,到这里的次数少了! 郁闷,乘积最大那题WA原来只是因为我用了pow函数引起的! Smith Number POJ强烈推荐50题 JOJ 2391 words POJ 1014 三十分钟掌握STL STL学习小记 POJ1003,简单题
POJ1006,中国剩余定理
saintqdd · 2007-08-04 · via 博客园 - saintqdd

此题是中国剩余定理的典型应用,具体解法是:

对于给定的p,e,i,他们分别是除23,28,33的余数。问题就是求除23余p,除28余e,除33余i,的最小数。是不是很熟悉啊,当然你也可以手算然后在用程序输出,不过这样做就没什么意思了。先求除23余p,除28余e的最小公共数。for循环求出p+23*i==e+28*j,即最小数minpe=p+23*i,公共数为minpe+gcd(23,28)*x,相同的方法在与最后一个数进行条件合并,最后可求得minpei+gcd(gcd(23,28),33)*x;我们想要的就是minpei+gcd(gcd(23,28),33);解毕.

POJ1006 code:

#include<iostream>
#define physical 23
#define emotional 28
#define mental 33

int gcd(int a,int b){
    int t1=a,t2=b,t;
    while(a%b!=0){
        t=a%b;
        a=b;
        b=t;
    }
    return (t1*t2)/b;
}
int main(){
    int p,e,i,d,j,k,P=1;
    while(scanf("%d%d%d%d",&p,&e,&i,&d)&&!(p==-1&&e==-1&&i==-1&&d==-1)){
        int pe=gcd(physical,emotional),minpe;

        for(j=0,k=0;;){
            if((p+physical*j)==(e+emotional*k))
                break;
            if((p+physical*j)<(e+emotional*k))
                j++;
            if((p+physical*j)>(e+emotional*k))
                k++;
        }

        minpe=p+physical*j;
        int pei=gcd(pe,mental),minpei;
        for(j=0,k=0;;){
            if((minpe+pe*j)==(i+mental*k))
                break;
            if((minpe+pe*j)<(i+mental*k))
                j++;
            if((minpe+pe*j)>(i+mental*k))
                k++;
        }       
        minpei=i+mental*k;
        if((minpei+pei-d)%pei==0)
            printf("Case %d: the next triple peak occurs in %d days.\n",P++,pei);
        else
            printf("Case %d: the next triple peak occurs in %d days.\n",P++,(minpei+pei-d)%pei);
    }
}