码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 1006 Biorhythms

时间:2014-09-21 12:39:00      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   ar   div   art   sp   

思路:伟大的中国同余定理。公式推导见这里:http://blog.csdn.net/shanshanpt/article/details/8724769

 

代码:

  

/*
  中国剩余定理:出自《孙子算经》
  
*/

#include<stdio.h>

#define MAX 21252

int main()
{
    int p, e, i, d, n, count = 0;
    
    while( scanf("%d%d%d%d", &p, &e, &i, &d) != EOF )
    {
                count++;
        if(p == -1 && e == -1 && i == -1 && d == -1)
        {
            break;
                }

        n = ( 5544 * p + 14421 * e + 1288 * i - d ) % MAX;
        
        if( n <= 0 )   // 范围限制 
        {
            n += 21252;
                }
        
        printf("Case %d: the next triple peak occurs in %d days.\n", count, n );
    }
    return 0;
}

 

POJ 1006 Biorhythms

标签:style   blog   http   color   io   ar   div   art   sp   

原文地址:http://www.cnblogs.com/ltwy/p/3984296.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!