HDU 5387 Clock (MUT#8 類比)

來源:互聯網
上載者:User

標籤:多校聯合

【題目連結】: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 類比)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.