hdu 1006 Tick and Tick 有技巧的暴力

Tick and Tick

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16707    Accepted Submission(s): 4083

Problem Description

The three hands of the clock are rotating every second and meeting each other many times everyday. Finally, they get bored of this and each of them would like to stay away from the other two. A hand is happy if it is at least D degrees from any of the rest. You are to calculate how much time in a day that all the hands are happy.

Input

The input contains many test cases. Each of them has a single line with a real number D between 0 and 120, inclusively. The input is terminated with a D of -1.

Output

For each D, print in a single line the percentage of time in a day that all of the hands are happy, accurate up to 3 decimal places.

Sample Input

0
120
90
-1

Sample Output

100.000
0.000
6.251

Author

PAN, Minghao

Source

ZJCPC2004

计算出每两个指针满足要求的角度所需的时间,及周期,然后按周期循环。

#include<iostream>
#include<stdio.h>
using namespace std;
double max(double a,double b,double c)
{
    double temp=(a>b)?a:b;
    return (temp>c)?temp:c;
}
double min(double a,double b,double c)
{
    double temp=(a<b)?a:b;
    return (temp<c)?temp:c;
}
int main()
{
    double wh=360.0/12/3600;
    double wm=360.0/60/60;
    double ws=360.0/60;
    double whm=wm-wh;
    double whs=ws-wh;
    double wms=ws-wm;
    //cout<<whm<<endl<<whs<<endl<<wms<<endl;
    double n;
    while(~scanf("%lf",&n)&&n!=-1)
    {
        double stahm=n/whm;
        double stahs=n/whs;
        double stams=n/wms;
        double endhm=(360-n)/whm;
        double endhs=(360-n)/whs;
        double endms=(360-n)/wms;
        double shm,shs,sms,ehm,ehs,ems;
        const double T_hm=43200.0/11,T_hs=43200.0/719,T_ms=3600.0/59;   //Ïà¶ÔÖÜÆÚ
        double sum=0;
        //cout<<"do"<<endl;
        for(shm=stahm,ehm=endhm; ehm<43200.000001; shm+=T_hm,ehm+=T_hm)
        {
            //cout<<shm<<endl;
            for(shs=stahs,ehs=endhs; ehs<43200.000001; shs+=T_hs,ehs+=T_hs)
            {
                if(ehm<shs) break;
                if(shm>ehs) continue;
                for(sms=stams,ems=endms; ems<43200.000001; sms+=T_ms,ems+=T_ms)
                {
                    if(ehm<sms||ehs<sms) break;
                    if(shm>ems||shs>ems) continue;
                    //cout<<"doing"<<endl;
                    double xsta=max(shm,shs,sms);
                    double xend=min(ehm,ehs,ems);
                    if(xsta<xend)
                        sum+=(xend-xsta);

                }
            }
        }
        printf("%.3lf\n",sum/432);

    }
    return 0;
}

时间: 2024-10-12 22:11:28

hdu 1006 Tick and Tick 有技巧的暴力的相关文章

HDU 1006 Tick and Tick 解不等式解法

一开始思考的时候觉得好难的题目,因为感觉很多情况,不知道从何入手. 想通了就不难了. 可以转化为一个利用速度建立不等式,然后解不等式的问题. 建立速度,路程,时间的模型如下: /*************************************************************************** * * * 秒钟的速度s=6°/s,分针是1/10°/s,时针是1/120°/s * * 所以相对速度s_m=59/10°/s,s_h=719/120°/s,m_h=12

HDU 1006 Tick and Tick(时钟,分钟,秒钟角度问题)

传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1006 Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 22203    Accepted Submission(s): 5877 Problem Description The three hands of the

hdu 1006 Tick and Tick

Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 19764    Accepted Submission(s): 5164 Problem Description The three hands of the clock are rotating every second and meeting each ot

HDU 1006 Tick and Tick 时钟指针问题

Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10194    Accepted Submission(s): 2859 Problem Description The three hands of the clock are rotating every second and meeting each ot

HDU1006 Tick and Tick【计算几何】

Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10770    Accepted Submission(s): 3008 Problem Description The three hands of the clock are rotating every second and meeting each o

Tick and Tick

The three hands of the clock are rotating every second and meeting each other many times everyday. Finally, they get bored of this and each of them would like to stay away from the other two. A hand is happy if it is at least D degrees from any of th

HDU 1006 模拟

Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 20120    Accepted Submission(s): 5262 Problem Description The three hands of the clock are rotating every second and meeting each ot

hdu 5024 Wang Xifeng&#39;s Little Plot【暴力dfs,剪枝】

2014年广州网络赛的C题,也是水题.要你在一个地图中找出一条最长的路,这条路要保证最多只能有一个拐角,且只能为90度 我们直接用深搜,枚举每个起点,每个方向进行dfs,再加上剪枝. 但是如果直接写的话,那一定会特别麻烦,再加上方向这一属性也是我们需要考虑的方面,我们将从别的地方到当前点的方向编一个号:往右为0,如下图顺时针顺序编号 (往右下方向为1,往下为2......以此类推) 我们知道了当前点的坐标,来到当前点的方向,以及到目前有没有拐弯,这几个属性之后,就可以记忆化搜索了,用一个四维数组

HDU 5024 Wang Xifeng&#39;s Little Plot(暴力枚举+瞎搞)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5024 Problem Description <Dream of the Red Chamber>(also <The Story of the Stone>) is one of the Four Great Classical Novels of Chinese literature, and it is commonly regarded as the best one. Thi