Tanky WooRSS

HDOJ 2076 夹角有多大(题目已修改,注意读题)

07 Aug 2010
这篇博客是从旧博客 WordPress 迁移过来,内容可能存在转换异常。

题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=2076


Algorithm Analyse 我们知道,时针走30°/小时,分针走6°/分钟。 所有 时针走:30°/h = 0.5°/m = (1/120)°/s 分针走: 6°/m = 0.1°/s 所有在h:m:s时,时针的角度为30h + m/2 + s/120;分针的角度为:6m + s/10; 所有它们的夹角为fabs(30h + m/2 + s/120 - 6m - s/10) = fabs(30h - 11m/2 - 11*s/120) 注意:在h>12时要减去12


// Author: Tanky Woo
// HDOJ 2076
// Accepted 2076 0MS 220K 490 B C++ Tanky Woo 
#include
#include 
#include 
using namespace std;

int main()
{
    int n;
    double h, m, s;  //虽然题目说是整数,但是用double无疑要方便多了

    scanf("%d", &n;);
    while (n-- && scanf("%lf %lf %lf", &h;, &m;, &s;))
    {
        if (h > 12) h -= 12;  // 注意!
        if(fabs(30*h-11*m/2-11*s/120) > 180)
            printf("%d\n", (int)(360-fabs(30*h-11*m/2-11*s/120)));
        else
            printf("%d\n", (int)(fabs(30*h-11*m/2-11*s/120)));
    }
    return 0;
}