HDU 5387 Clock
Clock
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 422 Accepted Submission(s): 294
Notice that the answer must be not more 180 and not less than 0
for each case,one line include the time
0≤hh<24,0≤mm<60,0≤ss<60
题意:给你一个时刻,求出时针与分针,分针与秒针。秒针与时针的夹角。
题解:分别求出时针。分针。秒针与12整点的夹角,求的时候把夹角*120。再求两两的夹角除以120.
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<cmath> #define ll int using namespace std; ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); } int main() { //freopen("test.in","r",stdin); int t; cin>>t; while(t--) { int h,m,s; scanf("%d:%d:%d",&h,&m,&s); if(h>=12)h-=12; ///ah=h*30+0.5*m+s/120 120为分母的公倍数 int ah=h*30*120+m*60+s;///时针与12正点的夹角*120 ///放大120倍是她为整数,以下同理 int am=m*6*120+s*12; int as=6*s*120; int gd=120; int a1,a2,a3; ///时-分 a1=ah>am?ah-am:am-ah; a1=a1>180*120?
360*120-a1:a1; ///分-秒 a2=am>as?am-as:as-am; a2=a2>180*120?
360*120-a2:a2; ///秒-时 a3=as>ah?as-ah:ah-as; a3=a3>180*120?360*120-a3:a3; if(a1%gd==0) printf("%d ",a1/gd); else printf("%d/%d ",a1/gcd(a1,gd),gd/gcd(a1,gd)); if(a3%gd==0) printf("%d ",a3/gd); else printf("%d/%d ",a3/gcd(a3,gd),gd/gcd(a3,gd)); if(a2%gd==0) printf("%d ",a2/gd); else printf("%d/%d ",a2/gcd(a2,gd),gd/gcd(a2,gd)); cout<<endl; } return 0; }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步