hdu1006

#include <iostream>
#include <cstdio>

using namespace std;

struct Segment
{
    double l, r;
}segment;

double mabs(double x)
{
    return x > 0 ? x : -x;
}

double d;

Segment method(double a, double b)
{
    Segment p;

    if (a > 0)
    {
        p.l = (d - b) / a;
        p.r = (360 - d - b) / a;
    }
    else if (a < 0)
    {
        p.r = (d - b) / a;
        p.l = (360 - d - b) / a;
    }

    if (p.l < 0)
    {
        p.l = 0;
    }

    if (p.r > 60)
    {
        p.r = 60;
    }

    if (p.l >= p.r)
    {
        p.l = p.r = 0;
    }

    return p;
}

Segment mixed(Segment a, Segment b)
{
    Segment p;
    p.l = max(a.l, b.l);
    p.r = min(a.r, b.r);

    if (p.l >= p.r)
    {
        p.l = p.r = 0;
    }

    return p;
}

double solve(double h, double m)
{
    Segment s[3][2];

    double a1, b1, a2, b2, a3, b3, sum = 0;

    a1 = 5.9, b1 = -6 * m;
    a2 = 719.0 / 120.0, b2 = -(30 * h + m / 2.0);
    a3 = 11.0 / 120, b3 = (66.0 * m - 360.0 * h) / 12.0;

    s[0][0] = method(a1, b1);
    s[0][1] = method(-a1, -b1);
    s[1][0] = method(a2, b2);
    s[1][1] = method(-a2, -b2);
    s[2][0] = method(a3, b3);
    s[2][1] = method(-a3, -b3);

    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            for (int k = 0; k < 2; k++)
            {
                segment = mixed(s[0][i], mixed(s[1][j], s[2][k]));
                sum += segment.r - segment.l;
            }
        }
    }

    return sum;
}

void input()
{
    while (cin >> d, d != -1)
    {
        double ans = 0.0;

        for (int i = 0; i < 12; i++)
        {
            for (int j = 0; j < 60; j++)
            {
                ans += solve(i, j);
            }
        }

        printf("%.3lf\n", ans / 432.0);
    }
}

int main()
{
    input();
    return 0;
}
假设现在的时钟是h小时,m分钟,s秒,给定的角度为degree;则列出happy的不等式有
时针到0时刻的角度的实际值为hw = (h+m/60+s/3600)*30,分针的角度mw = (m+s/60)*6,秒针的角度为sw = s*6;则他们都happy的条件为
degree<|hw -mw|<360 - degree;<1>
degree<|hw - sw|<360 - defgree;<2>
degree<|sw - mw|<360 - degree ;<3>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值