HDU 5387 Clock(模拟)

Clock

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1209    Accepted Submission(s): 685


Problem Description
Give a time.(hh:mm:ss),you should answer the angle between any two of the minute.hour.second hand
Notice that the answer must be not more 180 and not less than 0
 

Input
There are T (1T104) test cases
for each case,one line include the time

0hh<24, 0mm<60, 0ss<60
 

Output
for each case,output there real number like A/B.(A and B are coprime).if it's an integer then just print it.describe the angle between hour and minute,hour and second hand,minute and second hand.
 

Sample Input
 
   
4 00:00:00 06:00:00 12:54:55 04:40:00
 

Sample Output
 
   
0 0 0 180 180 0 1391/24 1379/24 1/2 100 140 120
Hint
每行输出数据末尾均应带有空格
 

Author
SXYZ
 

Source
2015 Multi-University Training Contest 8
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:   5994  5993  5992  5991  5990 

题意:给定一个时间,求出时针分针秒针两两夹角。
思路:选拔赛的时候做的一道题,当时没多少时间于是决定放弃这道题,结果今天搞了搞发现好简单,连对分数的处理也好简单,简直无语凝噎。思路就是先求 对角度,即时针距离0点的角度,分针距离0点的角度,秒针距离0点的角度,然后两两相减。分数的处理就是直接把减完的式子转化为分数形式,然后上下约分,如果分母是1直接输出分子,还有就是要求输出锐角,所以分子需要判断与360*120-分子的大小,如果大于就转化为360*120-分子。

#include 
#include 
#include 
#include 
#include 
using namespace std;

int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}

int main(){
	
	int t;
	scanf("%d",&t);
	while(t--){
		int h,m,s;
		scanf("%d:%d:%d",&h,&m,&s);
		int hhp,lhp,hmp,lmp,hsp,lsp;
		hhp=abs(h%12*3600-660*m-11*s);
		int sum=360*120-hhp;
		if(hhp>sum)
			hhp=sum;
		lhp=120;
		int k=gcd(hhp,lhp);
		hhp=hhp/k;
		lhp=lhp/k;
		if(lhp==1)
			printf("%d ",hhp);
		else
			printf("%d/%d ",hhp,lhp);
		hmp=abs(h%12*3600+60*m-719*s);
		lmp=120;
		sum=360*120-hmp;
		if(hmp>sum)
			hmp=sum;
		k=gcd(hmp,lmp);
		hmp/=k;
		lmp/=k;
		if(lmp==1)
			printf("%d ",hmp);
		else
			printf("%d/%d ",hmp,lmp);
		hsp=abs(720*m-708*s);
		lsp=120;
		sum=360*120-hsp;
		if(hsp>sum)
			hsp=sum;
		k=gcd(hsp,lsp);
		hsp/=k;
		lsp/=k;
		if(lsp==1)
			printf("%d \n",hsp);
		else
			printf("%d/%d \n",hsp,lsp);
	}
	return 0;
}


你可能感兴趣的:(算法,ACM)