HDU--1006
题目介绍
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
题目分析
根据三个指针的角速度不同来计算相应的时间。不能使用每秒的方式来计算,这样得到结果差别较大。代码中的 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的更多相关文章
- HDU 1006 [Tick Tick]时钟问题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1006 题目大意:钟表有时.分.秒3根指针.当任意两根指针间夹角大于等于n°时,就说他们是happy的, ...
- HDU 1006 Tick and Tick(时钟,分钟,秒钟角度问题)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1006 Tick and Tick Time Limit: 2000/1000 MS (Java/Oth ...
- HDU 1006 Tick and Tick 解不等式解法
一開始思考的时候认为好难的题目,由于感觉非常多情况.不知道从何入手. 想通了就不难了. 能够转化为一个利用速度建立不等式.然后解不等式的问题. 建立速度,路程,时间的模型例如以下: /******** ...
- HDU 1006 Digital Roots
Problem Description The digital root of a positive integer is found by summing the digits of the int ...
- HDU 1006 Tick and Tick 时钟指针问题
Tick and Tick Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1006(时钟指针转角 **)
题意是说求出在一天中时针.分针.秒针之间距离均在 D 度以上的时间占比. 由于三针始终都在转动,所以要分别求出各个针之间的相对角速度,分别求出三针满足角度差的首次时间,再分别求出不满足角度差的最终时间 ...
- [ACM_模拟] HDU 1006 Tick and Tick [时钟间隔角度问题]
Problem Description The three hands of the clock are rotating every second and meeting each other ma ...
- hdu 1006 Tick and Tick 有技巧的暴力
Tick and Tick Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdu 1006 Tick and Tick
Tick and Tick Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1006 模拟
Tick and Tick Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
随机推荐
- 微软宣布.NET开发环境将开源 支持Mac OS X和Linux
微软宣布.NET开发环境将开源 支持Mac OS X和Linux 投递人 itwriter 发布于 2014-11-13 06:58 评论(55) 有4388人阅读 原文链接 [收藏] « » ...
- jquery 超简单的点赞效果
1.HTML(可以优化一下,尽量少些几个标签.....) <div id="dianz"> <b class="cz"><em&g ...
- QT5.4 vs2013静态加载插件的sqlite静态编译
1. 非常多同学在静态编译QT5完毕后, sqlite的驱动老是载入不进去, 原因可能是由于你没有例如以下操作: #include <QtPlugin> Q_IMPORT_PLUGIN(Q ...
- cocos2d的-X- luaproject的LUA脚本加密
2014/1/26 更新 近期又发现了一个非常easy的方法,事实上coco2dx已经给我们提供设置loader的方法. 注意:有个局限性,在非android平台下调用pEngine->exec ...
- Scala开发环境搭建与资源推荐
Scala开发环境搭建与资源推荐 本文介绍了Scala的开发环境,包括SDK.IDE的设置.常用资源列表等.Scala是一门静态语言,很有可能就是Java的继承者. AD: 2014WOT全球软件技术 ...
- [转]How To Use CSS3 Media Queries To Create a Mobile Version of Your Website
CSS3 continues to both excite and frustrate web designers and developers. We are excited about the p ...
- 泛型Hub
SignalR循序渐进(二)泛型Hub 接上一篇,文章末尾抛出了2个问题: 能不能让客户端声明一个强类型的方法列表呢?这样首先不容易写错. 同样的,能不能让服务端声明一个强类型的方法列表给客户端调用呢 ...
- asp.net mvc4
select省市联动选择城市 asp.net mvc4 2014-05-24 16:48 by P.C ++, 159 阅读, 2 评论, 收藏, 编辑 本文在 http://www.cnblogs. ...
- java反射拼接方法名动态执行方法
近期由于负责项目的一个模块,该模块下有很多分类,每个分类都有一个编码code,这个值是作为一个参数携带过来的.但是每个code确实对应一个方法的. code的值有很多个,自己又不想做ifelse或者s ...
- MVC 在控制器中获取某个视图动态的HTML代码
ASP.NET MVC 在控制器中获取某个视图动态的HTML代码 如果我们需要动态的用AJAX从服务器端获取HTML代码,拼接字符串是一种不好的方式,所以我们将HTML代码写在cshtml文件中, ...