Loading [MathJax]/extensions/TeX/AMSsymbols.js

2015年10月21日 星期三

Uva 756 Biorhythms

#uva 756 #Biorhythms


題意:中國餘數定理的裸題,

INPUT=>a b c d 
OUTPUT=> ans

其中  (ans+d)%23==a,(ans+d)%28==b,,(ans+d)%33==c

胡言亂語:因此可以先求出(ans+d)在-d就是答案了!

這題簡單來說就是中國餘數定理(點我),帶入公式就是答案的 =)

程式碼:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
using namespace std;
int GCD(int p,int q){
while(p%=q)
swap(p,q);
return q;
}
int LCM(int a, int b) {
if(a<b) swap(a,b);
return a*b/GCD(a, b);
}
int test(int K2, int K) {
int temp = K2;
while (true) {
if (K2 % K == 1) break;
else
K2 += temp;
}
return K2;
}
int main(){
int Biorhythms = 23*28*33 ,k = 0,a ,b, c ,d,ans;
int aa = test(28*33,23);
int cc = test(23*28,33);
int bb = test(23*33,28);
while(scanf("%d %d %d %d",&a,&b,&c,&d)==4){
k++;
if(a==-1 and b==-1 and c==-1 and d==-1) break;
ans = (aa*a+bb*b+cc*c-d+Biorhythms)%Biorhythms;
if(!ans) ans = Biorhythms;
printf("Case %d: the next triple peak occurs in %d days.\n",k,ans);
}
}
view raw Uva 756.cpp hosted with ❤ by GitHub

有點想睡...但好像原本要讀計組的說@@

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。