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): 16633    Accepted Submission(s): 4059

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

之前一秒一秒离散地模拟,一直wa。

最后看了题解,是看作连续来做。

由角速度求出相对角速度,再求出每两根针的周期(经过多久再次重合)。然后求12个小时内每两根针(3组)每个周期happy time的交集的和。

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

const double h_m=11.0/120,h_s=719.0/120,m_s=59.0/10;    //相对角速度
const double Th_m=43200.0/11,Th_s=43200.0/719,Tm_s=3600.0/59;  //周期

int main()
{
    double d;
    while(scanf("%lf",&d)!=EOF&&d>=0)
    {
        ///d/h_m
        double sh_m=d/h_m;
        double eh_m=(360.0-d)/h_m;
        double sh_s=d/h_s;
        double eh_s=(360.0-d)/h_s;
        double sm_s=d/m_s;
        double em_s=(360.0-d)/m_s;
        double s1,e1,s2,e2,s3,e3,s4,e4,res=0;
        for(s1=sh_m,e1=eh_m;e1<=43200.000001;s1+=Th_m,e1+=Th_m)
        {
            for(s2=sh_s,e2=eh_s;e2<=43200.000001;s2+=Th_s,e2+=Th_s)
            {
                if(e1<=s2)
                    break;
                if(e2<=s1)
                    continue;
                for(s3=sm_s,e3=em_s;e3<=43200.000001;s3+=Tm_s,e3+=Tm_s)
                {
                    if(s3>=e2||s3>=e1)
                        break;
                    if(e3<=s2||e3<=s1)
                        continue;
                    s4=max(s1,max(s2,s3));
                    e4=min(e1,min(e2,e3));
                    res+=(e4-s4);
                }
            }
        }
        printf("%.3lf\n",res/432);
    }
    return 0;
}
时间: 2024-10-07 19:43:47

HDU_1006_Tick and Tick的相关文章

SylixOS BSP tick驱动流程

SylixOS BSP tick驱动流程 1. 开发环境 - 操作系统:SylixOS - 编程环境:RealEvo-IDE3.1 - 硬件平台:IMX6Q实验箱 2.技术实现 时钟节拍(clock tick)是特定的周期性中断.这个中断可以看做是系统心脏的脉动.时钟的节拍式中断使得内核可以将任务延时若干个整数时钟节拍,同时当任务等待事件发生时,提供等待超时的依据. 2.1 Tick的频率设置 Tick的频率需要根据具体的硬件性能来设置.频率越快,系统的额外开销也会越大.SylixOS中频率通

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 ot

程序猿的量化交易之路(29)--Cointrader之Tick实体(16)

转载需注明出处:http://blog.csdn.net/minimicall,http://cloudtrade.top Tick:什么是Tick,在交易平台中很常见,事实上就 单笔交易时某仅仅证券的基本数据. 我们通过代码来学习吧: package org.cryptocoinpartners.schema; import javax.annotation.Nullable; import javax.persistence.Entity; import javax.persistence.

进入OS前的两步之System tick

OK,继续向操作系统迈进.由简入繁,先实现两个小功能.第一个是system tick,第二个是任务切换(PendSV).一个是操作系统的心跳,一个是操作系统的并发处理的具体实现. System tick,在裸机程序里面,这个功能一直是用来做延时功能用的,用STM32做项目,基本都会用到.这里不准备再从头去实现这个功能,而是直接用ST官方的库文件.库文件版本为3.5.0. 主要用到两个函数,第一个为 static __INLINE uint32_t SysTick_Config(uint32_t

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

Jmeter &amp; TICK

背景: 本来只是想在将Jmeter的测试结果写入InfluxDB, 但发现从InfluxDB V1.3后开始, 已经不支持Web Admin interface, 才发现InfluxData 搞了一个整体产品栈,名字叫做TICK Telegraf InfluxDB Chronograf Kapacitor 前提: 有一台Linux Server (Redhat 6), IP为:172.20.184.157, 可以通过sudo 安装软件包 安装 1. 先下载 https://dl.influxda

TICK技术栈 -- DevOps轻量级监控解决方案

了解和学习TICK栈不久,还有很多需要进一步深入.但我个人非常看好这个项目,也希望更进一步研究,可能的话,会在生产环境谨慎和大胆地尝试一下.同时,在阅读源码和二次开发中,希望技术上能有所提升. TICK技术栈 简介 T = Telegraf is a plugin-driven server agent for collecting and reporting metrics. I = InfluxDB is a time series database built from the groun

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

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