Biorhythms POJ 1006 uva 756 (同余) HQG_AC

实际上这是一个同余问题。

可以应用中国剩余定理。我是直接暴力求解。

注意格式

#include<bits/stdc++.h>
using namespace std;
int main(){
    int p,e,i,d,count,x,n;
    scanf("%d",&n);
    while(n--){
        count=0 ;
        while(scanf("%d%d%d%d",&p,&e,&i,&d)!=EOF){
            if (p==-1) break ;
            x=(5544*p+14421*e+1288*i-d+21252)%21252;//之前得到的式子
            if (x==0) x=21252;
            printf("Case %d: the next triple peak occurs in %d days.\n",++count,x) ;
        }
        if(n!=0) printf("\n");
    }
    return 0 ;
}

uva:

#include<bits/stdc++.h>
using namespace std;
int main(){
    int p,e,i,d,count=0,x,n;
    while(cin>>p>>e>>i>>d,p!=-1){
         x=(5544*p+14421*e+1288*i-d+21252)%21252;//之前得到的式子
         if (x==0) x=21252;
         printf("Case %d: the next triple peak occurs in %d days.\n",++count,x) ;
    }
}

猜你喜欢

转载自blog.csdn.net/HQG_AC/article/details/81226434