標籤:多校聯合
【題目連結】:click here~~
【題目大意】給定一個時間點,求時針和分針夾角,時針和秒針夾角,分針和秒針夾角
類比題,注意細節
代碼:
#include<bits/stdc++.h>using namespace std;inline int read(){ int c=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){c=c*10+ch-'0';ch=getchar();} return c*f;}int gcd(int a,int b){return b==0?a:gcd(b,a%b);}int main(){ int t,h,m,s; t=read(); while(t--){ scanf("%d:%d:%d",&h,&m,&s); h%=12; m%=60; s%=60; int ss=s*720; //秒針走過的角度 int mm=720*m+12*s; //分針走過的角度 int hh=3600*h+60*m+s; //時針走過的角度 //計算角度之差 int hm=abs(hh-mm); int hs=abs(hh-ss); int ms=abs(mm-ss); //判斷 hm=min(hm,120*360-hm); hs=min(hs,120*360-hs); ms=min(ms,120*360-ms); //取最大公約數 int ghm=gcd(hm,120); int ghs=gcd(hs,120); int gms=gcd(ms,120); if(ghm==120) cout<<hm/120; else cout<<hm/ghm<<"/"<<120/ghm; if(ghs==120) cout<<" "<<hs/120<<" "; else cout<<" "<<hs/ghs<<"/"<<120/ghs<<" "; if(gms==120) cout<<ms/120<<" "<<endl; else cout<<ms/gms<<"/"<<120/gms<<" "<<endl; } return 0;}
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。
HDU 5387 Clock (MUT#8 類比)