题目介绍

  1. 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.

  2. 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.

  3. 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.

  4. Sample Input

    0
    120
    90
    -1
  5. Sample Output

    100.000
    0.000
    6.251

题目分析

根据三个指针的角速度不同来计算相应的时间。不能使用每秒的方式来计算,这样得到结果差别较大。代码中的 periodSH 在一圈也就是 360 度内,到达同样相隔角度所需的时间,其实也就是快的指针比慢的指针多走了 360 度,这样就容易理解多了。

代码

#include <iostream>
#include <iomanip> using namespace std; const double vS = 6;
const double vM = 1/10.0;
const double vH = 1/120.0; const double deltaVSH = vS - vH;
const double deltaVSM = vS - vM;
const double deltaVMH = vM - vH; const double periodSH = 360 / deltaVSH;
const double periodSM = 360 / deltaVSM;
const double periodMH = 360 / deltaVMH; const double halfDay = 12 * 60 * 60; #define MAX(a,b,c) (a>b?(a>c?a:c):(b>c?b:c))
#define MIN(a,b,c) (a<b?(a<c?a:c):(b<c?b:c)) int main()
{
int degree = 0;
double bSH=0, bSM=0, bMH=0;
double eSH=0, eSM=0, eMH=0;
double time = 0;
while(cin>>degree && degree!=-1)
{
time = 0;
bSH = degree / deltaVSH;
bSM = degree / deltaVSM;
bMH = degree / deltaVMH; eSH = (360 - degree) / deltaVSH;
eSM = (360 - degree) / deltaVSM;
eMH = (360 - degree) / deltaVMH; for(double btSH=bSH, etSH=eSH; etSH < halfDay+0.0000001; btSH+=periodSH, etSH+=periodSH)
{
for(double btSM=bSM, etSM=eSM; etSM < halfDay+0.0000001; btSM+=periodSM, etSM+=periodSM)
{
if(etSM < btSH)
{
continue;
}
if(btSM > etSH)
{
break;
}
for(double btMH=bMH, etMH=eMH; etMH < halfDay+0.0000001; btMH+=periodMH, etMH+=periodMH)
{
if(etMH<btSM || etMH<btSH)
{
continue;
}
if(btMH>etSH || btMH>etSM)
{
break;
}
time += MIN(etSH,etSM,etMH) - MAX(btSH,btSM,btMH);
}
}
}
cout.setf(ios::fixed);
cout<<setprecision(3)<<time/halfDay*100<<endl;
}
return 0;
}

HDU--1006的更多相关文章

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

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

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

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

  3. HDU 1006 Tick and Tick 解不等式解法

    一開始思考的时候认为好难的题目,由于感觉非常多情况.不知道从何入手. 想通了就不难了. 能够转化为一个利用速度建立不等式.然后解不等式的问题. 建立速度,路程,时间的模型例如以下: /******** ...

  4. HDU 1006 Digital Roots

    Problem Description The digital root of a positive integer is found by summing the digits of the int ...

  5. HDU 1006 Tick and Tick 时钟指针问题

    Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  6. HDU 1006(时钟指针转角 **)

    题意是说求出在一天中时针.分针.秒针之间距离均在 D 度以上的时间占比. 由于三针始终都在转动,所以要分别求出各个针之间的相对角速度,分别求出三针满足角度差的首次时间,再分别求出不满足角度差的最终时间 ...

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

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

  8. hdu 1006 Tick and Tick 有技巧的暴力

    Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  9. hdu 1006 Tick and Tick

    Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  10. HDU 1006 模拟

    Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

随机推荐

  1. AJAX入门——工作原理

    同步和异步交互,了解互动 对于一个样本:一般B/S模式(同步)       AJAX技术(异步)        *  同步:       提交请求->等待server处理->处理完成返回 ...

  2. asp.net如何实现word文档在线预览

    原文:asp.net如何实现word文档在线预览 实现方式:office文档转html,再在浏览器里面在线浏览 1.首先引入com组件中office库,然后在程序集扩展中引入word的dll 2.将M ...

  3. js判断浏览器类型(手机和电脑终端)

    工作中经常会用到通过js来判断浏览器的功能!今天这里通过js来判断浏览器是来自移动设备还是pc设备! 代码如下: var browser={ versions:function(){ var u = ...

  4. sqlclr创建表值函数案例

    ----------------------------------------------:定义表值类型:(1.一定返回的是IEnumerable2.一定带参数3.一定有FillRowMethodN ...

  5. 看精通SQL SERVER2008有感1

    SQLserver数据库中的其他数据库作用: Master:存储SQLserver所有的全局配置,也就是存储SQLserver所知道的关于自己的全部信息,包括自身的配置,和当前的状态,这些数据存储在系 ...

  6. 浅谈DevExpress<一>:换肤

    最近要用到devExpress,一句话,很好很强大,比起vs自带的winform界面,种类和花样要多了不少,然而,强力的功能带来了庞大的信息量,所以我打算通过一些小模块来和大家一起对它进行探讨和研究. ...

  7. C++中文件的操作

    #include <iostream> #include <fstream> using namespace std; int main() { char s[27],m[27 ...

  8. Restful?

    为什么要Restful?为什么不Restful?   本随笔不说为什么要Restful,只说为什么不Restful.首先Http是超文本转移协议而不是控制协议.通常文档中也会使用“资源”来指代超文本. ...

  9. Microsoft Push Notification Service(MPNS)的最佳体验

    如何获得 Microsoft Push Notification Service(MPNS)的最佳体验 有很多同学抱怨MPNS的各种问题,其中包括服务超时.返回各种错误代码不知如何处理等等..今天我用 ...

  10. window wamp下xhprof的安装使用,Graphviz配置

    在新的工作安排下来前赶紧把手上工作优化下,本来是靠xdebug+grindview来的,不过还是麻烦,就换上这个轻量级的性能测试了.网上搜的大多都是lamp环境下的,wamp下的倒是不多,而且不好用, ...