首页 > 代码库 > HDOJ 5387 Clock 水+模拟

HDOJ 5387 Clock 水+模拟


Clock

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


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
每行输出数据末尾均应带有空格
 

Source
2015 Multi-University Training Contest 8
 

/* ***********************************************
Author        :CKboss
Created Time  :2015年08月13日 星期四 22时23分29秒
File Name     :HDOJ5387.cpp
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

int hh,mm,ss;

int alltime(int h,int m,int s)
{
	return h*3600+m*60+s;
}

const int mod=360*120;

int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);

	int T_T;
	scanf("%d",&T_T);
	while(T_T--)
	{
		scanf("%d:%d:%d",&hh,&mm,&ss);

		int at=alltime(hh,mm,ss);
		int hhdu=at%mod;
		int mmdu=12*at%mod;
		int ssdu=720*at%mod;

		int dur_hm=abs(mmdu-hhdu);
		if(dur_hm>mod/2) dur_hm=mod-dur_hm;

		int dur_hs=abs(hhdu-ssdu);
		if(dur_hs>mod/2) dur_hs=mod-dur_hs;

		int dur_ms=abs(mmdu-ssdu);
		if(dur_ms>mod/2) dur_ms=mod-dur_ms;

		int g1=__gcd(dur_hm,120);
		int g2=__gcd(dur_hs,120);
		int g3=__gcd(dur_ms,120);

		///print dur_hm
		if(g1==120) printf("%d ",dur_hm/g1);
		else printf("%d/%d ",dur_hm/g1,120/g1);

		///print dur_hs
		if(g2==120) printf("%d ",dur_hs/g2);
		else printf("%d/%d ",dur_hs/g2,120/g2);

		///print dur_hs
		if(g3==120) printf("%d \n",dur_ms/g3);
		else printf("%d/%d \n",dur_ms/g3,120/g3);
	}
    
    return 0;
}






HDOJ 5387 Clock 水+模拟