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 ...
随机推荐
- 对web.config的ConnectionString加密
原文:对web.config的ConnectionString加密 本文参考了wayshan的博客,原文地址:http://www.cnblogs.com/wayshan/archive/2012/0 ...
- VS2015 Apache Cordova
VS2015 Apache Cordova第一个Android和IOS应用 前言 本人个人博客原文链接地址为http://aehyok.com/Blog/Detail/75.html. http: ...
- leetcode N-QueensII
题目和上一题一样,就是要求输出有多少种结果.最直接的就是,只要在上一题的代码return ans.size();就可以了.果然也是AC了. 然后我翻看了几种别人写的,暂时还没有找到复杂度可以比上一题降 ...
- SuspendLayout()了解方法
SuspendLayout()暂时挂起的布局逻辑控制(msdn),它ResumeLayout()在会同.我的理解是,使用SuspendLayout()让整个窗体站,等到所有的东西都设置齐全,然后Re ...
- 开源文档管理系统LogicalDOC测试报告---安装篇
开源文档管理系统LogicalDOC测试报告---安装篇 分类: Linux2011-06-22 15:40 7436人阅读 评论(3) 收藏 举报 文档管理测试mysql数据库installerja ...
- 手机新闻网站,掌上移动新闻,手机报client,jQuery Mobile手机新闻网站,手机新闻网站demo,新闻阅读器开发
我们坐在地铁,经常来查看新浪手机新闻,腾讯新闻.或者刷微信看新闻更多功能.你有没有想过如何实现这些目标.移动互联网,更活泼. 因为HTML5到,jQuery Moblie到.今天我用jqm为了给你一个 ...
- Bootstrap 图标
Bootstrap 图标由 Glyphicons 提供.详情可以去bootstrap官网进行查看. 用法: <i class="icon_class_name">< ...
- keepalive学习
keepalive学习之软件设计 软件架构如下图所示: Keepalived 完全使用标准的ANSI/ISO C写出. 该软件主要围绕一个中央I/O复用分发器而设计,这个I/O复用分发器提供网络实时功 ...
- 在C#代码中应用Log4Net系列教程
在C#代码中应用Log4Net系列教程(附源代码) Log4Net应该可以说是DotNet中最流行的开源日志组件了.以前需要苦逼写的日志类,在Log4Net中简单地配置一下就搞定了.没用过Log4 ...
- 浅谈JavaScript中的call和apply
语法 fun.apply(thisArg, [argsArray]) fun.call(thisArg, arg1, arg2, ...) apply 接收两个参数,第一个参数指定了函数体内this对 ...