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 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
 
题意:时针,分针和秒针都厌倦了其余两针,只有在与其余两针保持n度以上的距离才能感到高兴。问一天中,三针都高兴的时间占总时间的百分比。注意时间是连续的。
 
分析:
时间是连续的,不能枚举。。我一开始就去枚举。。。
推荐一个大神的题解:(我的太垃圾)
不要脸的贴一下代码:
复制代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define max_v 10000
int main()
{
    int t;
    double n,sum,ft1,ft2,ft3,et1,et2,et3,max,min;
    double sm,sh,mh,tsm,tsh,tmh,fsm,fsh,fmh,esm,esh,emh;
    sm=10./59.;
    sh=120./719.;
    mh=120./11.;
    tsm=360*sm;
    tsh=360*sh;
    tmh=360*mh;
    while(~scanf("%lf",&n))
    {
        if(n<0)
            break;
        sum=0;
        fsm=sm*n;
        fsh=sh*n;
        fmh=mh*n;
        esm=tsm-fsm;
        esh=tsh-fsh;
        emh=tmh-fmh;
        for(ft3=fmh,et3=emh;et3<=43200;et3+=tmh,ft3+=tmh)
        {
            for(ft2=fsh,et2=esh;et2<=43200;et2+=tsh,ft2+=tsh)
            {
                if(et2<ft3)
                    continue;
                if(ft2>et3)
                    break;
                for(t=0,ft1=fsm,et1=esm;et1<=43200;t=t+1,et1=esm+t*tsm,ft1=fsm+t*tsm)
                {
                    if(et1<ft3 || et1<ft2)
                        continue;
                    if(ft1>et3 || ft1>et2)
                        break;
                    max=ft1;
                    if(ft2>max)
                        max=ft2;
                    if(ft3>max)
                        max=ft3;
                    min=et1;
                    if(et2<min)
                        min=et2;
                    if(et3<min)
                        min=et3;
                    sum+=min-max;
                }
            }
        }
        sum/=432.;
        printf("%.3lf\n",sum);
    }
    return 0;
}
复制代码

 

 
posted @   西*风  阅读(963)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示