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 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
分析:

三个指针走的角速度:

秒针速度S = 6°/s,分针速度M = (1/10)°/s,时针速度H = (1/120)°/s

这三个指针两两之间的相对速度差为:

秒时相差S_H = (719/120)°/s,秒分相差S_M = (59/10)°/s,分时相差M_H = (120/11)°/s

相差一度需要的时间为

秒时相差SH = (120/719)s/度,秒分相差SM = (10/59)s/度,分时相差MH = (120/11)s/度

相差360°需要的时间为

秒时相差tSH = 43200.0/719,秒分相差tSM = 3600.0/59,分时相差tMH = 43200.0/11

算出两两指针在43200s(12小时)内满足条件时间的区间的交集。

代码:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>

using namespace std;
///秒针角速度 6度/s, 分针0.1度/s,时针1/120度/s
const double sh = 719.0/120 , sm = 59.0/10, mh = 11.0/120;///三个指针两两相对角速度。
const double tsh = 43200.0 / 719, tsm = 3600.0 / 59, tmh = 43200.0 / 11;///三个指针两两相差360度所需的时间。
///将相对角速度变成周期。(即两针间需要多久出现夹角的循环)
/// 同样可求得三个周期的最小公倍数为 43200 秒,即12小时,

double max1(double a, double b, double c)
{
return max(a, max(b, c));
}
double min1(double a, double b, double c)
{
return min(a, min(b, c));
}
int main(void)
{
int D;

while(scanf("%d", &D), D != -1)
{
double bsh, bsm, bmh, esh, esm, emh, total, beginn, endd;
///第一次满足条件的时间。(开始时间)
bsh = D / sh;
bsm = D / sm;
bmh = D / mh;
///第一次出现不满足条件的时间。(结束时间)
esh = (360 - D) / sh;
esm = (360 - D) / sm;
emh = (360 - D) / mh;

total = 0;

for(double bt1 = bsh, et1 = esh; et1<= 43200.000001; bt1 += tsh, et1 += tsh)
{
for(double bt2 = bsm, et2 = esm; et2 <= 43200.000001; bt2 += tsm, et2 += tsm)
{
///判断是否有交集。
if(bt2 > et1)
break;

if(et2 < bt1)
continue;

for(double bt3 = bmh, et3 = emh; et3 <= 43200.000001; bt3 += tmh, et3 += tmh)
{
if(bt3 > et1 || bt3 > et2)
break;

if(et3 < bt1 || et3 < bt2)
continue;

beginn = max1(bt1, bt2, bt3);
endd = min1(et1, et2, et3);

total += (endd - beginn);
}

}
}

printf("%.3f\n", total / 432);

}
return 0;
}

HDU 1006 模拟的更多相关文章

  1. [ACM_模拟] HDU 1006 Tick and Tick [时钟间隔角度问题]

    Problem Description The three hands of the clock are rotating every second and meeting each other ma ...

  2. HDU 1006 [Tick Tick]时钟问题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1006 题目大意:钟表有时.分.秒3根指针.当任意两根指针间夹角大于等于n°时,就说他们是happy的, ...

  3. hdu 4891 模拟水题

    http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...

  4. hdu 5012 模拟+bfs

    http://acm.hdu.edu.cn/showproblem.php?pid=5012 模拟出骰子四种反转方式,bfs,最多不会走超过6步 #include <cstdio> #in ...

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

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1006 Tick and Tick Time Limit: 2000/1000 MS (Java/Oth ...

  6. hdu 4669 模拟

    思路: 主要就是模拟这些操作,用链表果断超时.改用堆栈模拟就过了 #include<map> #include<set> #include<stack> #incl ...

  7. 2013杭州网络赛C题HDU 4640(模拟)

    The Donkey of Gui Zhou Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  8. HDU/5499/模拟

    题目链接 模拟题,直接看代码. £:分数的计算方法,要用double; #include <set> #include <map> #include <cmath> ...

  9. hdu 5003 模拟水题

    http://acm.hdu.edu.cn/showproblem.php?pid=5003 记得排序后输出 #include <cstdio> #include <cstring& ...

随机推荐

  1. 【聚类评价】Calinski-Harabaz(CH)

    Calinski-Harabaz(CH) CH指标通过计算类中各点与类中心的距离平方和来度量类内的紧密度,通过计算各类中心点与数据集中心点距离平方和来度量数据集的分离度,CH指标由分离度与紧密度的比值 ...

  2. P1559 运动员最佳匹配问题 by hyl 天梦

    #include<iostream> using namespace std; int n; int maxx[21][21]; int lie[21]; int aa[21]; int ...

  3. PowerDesigner配置Oracle数据库反向工程

    PowerDesigner配置Oracle数据库反向工程 作者:Jesai 贴吧:软件频道吧 1. 前言: PowerDesigner是Sybase的企业建模和设计解决方案,采用模型驱动方法,将业务与 ...

  4. Kettle自定义jar包供javascript使用

    我们都知道 Kettle 是用 Java 语言开发,并且可以在 JavaScript 里面直接调用 java 类方法.所以有些时候,我们可以自定义一些方法,来供 JavaScript 使用. 本篇文章 ...

  5. .net core 连接数据库(通过数据库生成Modell)

    创建数据库 (扫盲贴还劳烦大神们勿喷,谢谢) 打开数据库 输入如下代码 创建数据库 CREATE DATABASE [Blogging]; GO USE [Blogging]; GO CREATE T ...

  6. QTP测试web时:打开ie浏览器进行录制但qtp录制脚本为空

    1. 关闭ie的保护模式:设置——internet选项——安全——取消勾选“启用保护模式” 这一步很关键,之前试过很多步骤,只有这个成功了. 修改后如果可行即可.如果不行再进行下面操作: 2.关闭杀毒 ...

  7. 06hive企业调优

    一.Fetch抓取 Fetch抓取是指,Hive 中对某些情况的查询可以不必使用MapReduce计算. 在 hive-default.xml.template 文件中 hive.fetch.task ...

  8. js 获取元素坐标 和鼠标点击坐标

    js 获取元素的位置 var odiv=document.getElementById('divid'); alert(odiv.getBoundingClientRect().left); aler ...

  9. 定义可选URL片段 定义自定义片段变量 精通ASP-NET-MVC-5-弗瑞曼

  10. testng使用详解

    一.testng 介绍 TestNG 是一个测试框架,其灵感来自 JUnit 和 NUnit,但同时引入了一些新的功能,使其功能更强大,使用更方便. TestNG 设计涵盖所有类型的测试:单元,功能, ...