码迷,mamicode.com
首页 > 其他好文 > 详细

hihocoder-1562-Hi的钟表

时间:2017-08-28 00:48:12      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:tps   amp   title   单点   http   多少   ace   .com   head   

hihocoder-1562-Hi的钟表

1562 : ?Hi的钟表

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

?Hi喜欢各种?度。?天,他注意到了钟表上的?度,于是他想考考他的好朋友?Ho:对于?个24?时制的时刻,在 t 秒之后,对应在钟表上时针与分针的夹?是多少。为保证答案的唯?性,只需考虑不超过180°的?。你能帮助?Ho解决这个问题吗?  

例如,下图可表?15点30分0秒经过0秒后的时间,其对应的夹?为75°和285°,在这个问题中我们只考虑不超过180°的?,所以此时的夹?为75°。

技术分享

输入

输?包含多组测试数据。

第??为测试数据的组数T(1 ≤ T ≤ 1000)  

对于每组数据:  

第??包含三个整数hms,表?给定时刻的时、分、秒(0 ≤ h ≤ 23,0 ≤ m ≤ 59,0 ≤ s ≤ 59)  

第??包含?个整数t,表?经过的秒数(0 ≤ t ≤ 1000000000)

输出

对于每组数据,输出时针与分针的夹角。四舍五?保留?数点后四位。

样例输入
3
15 30 0
0
14 30 0
3600
15 30 0
3600
样例输出
75.0000
75.0000
45.0000

 

 

#include <cstdio>  
#include <cstring> 

#include <cmath>

#include <iostream>  
using namespace std; 

double ComputeAngle(int h, int m, int s){
	double m_angle = m * 360.0 / 60.0 + (s/60.0)*6.0;  
	while(m_angle > 360.0){
		m_angle -= 360.0; 
	}
	
	double h_angle = h * 360.0 / 12.0 + (m_angle / 360.0)*30.0; 
	while(h_angle > 360.0){
		h_angle -= 360.0; 
	}

	double ans = max(m_angle, h_angle) - min(m_angle, h_angle); 
	ans = min(360.0 - ans, ans);  
	return ans; 
}

int main(){

	int T, t, s, h, m;
	double ans;  
	scanf("%d", &T); 
	while(T--){
		scanf("%d %d %d", &h, &m, &s); 
		scanf("%d", &t); 

		h += t / 3600; 
		h %= 12;

		t = t % 3600;  

		m += t / 60; 
		if(m >= 60){
			m %= 60; 
			h = (h + 1)% 12; 
		} 
		t = t%60; 

		s += t; 
		if(s >= 60){
			s %= 60; 
			m = m + 1; 
			if(m >= 60){
				m %= 60; 
				h = (h + 1)%12; 
			}
		}

		ans = ComputeAngle(h, m, s); 

		printf("%.4lf\n", ans ); 
	}
	return 0; 
} 

  

 

hihocoder-1562-Hi的钟表

标签:tps   amp   title   单点   http   多少   ace   .com   head   

原文地址:http://www.cnblogs.com/zhang-yd/p/7440891.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!