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 ...
随机推荐
- 再谈ORACLE CPROCD进程
罗列一下有关oprocd的知识点 oprocd是oracle在rac中引入用来fencing io的 在unix系统下,假设我们没有採用oracle之外的第三方集群软件,才会存在oprocd进程 在l ...
- Web前端框架与类库
Web前端框架与类库的思考 说起前端框架,我也是醉了.现在去面试或者和同行聊天,动不动就这个框架碉堡了,那个框架好犀利. 当然不是贬低框架,只是有一种杀鸡焉用牛刀的感觉.网站技术是为业务而存在的,除此 ...
- hibernate配置jndi
tomcat里的conf->context.xml <Resource name="mysql" auth="Container" type ...
- 使用vs2010复制粘贴代码时特别卡用一段时间就特别卡重启也没用
vs2010编写代码一段时间后复制粘贴特别卡,下拉条也特别卡,这个状况困扰了我两个月,实在忍不住了,去网上搜了搜 有网友说是快捷键冲突,所以我就把其他程序结束了,结果莫名奇妙的瞬间就不卡了.最终弄明白 ...
- S全选功能代码
JS全选功能代码优化 2014-06-26 00:00 by 龙恩0707, 470 阅读, 3 评论, 收藏, 编辑 JS全选功能代码优化 最近在看javascript MVC那本书,也感觉到自己写 ...
- Docker 01 Introduction
Docker的组成: Docker Engine,一个轻量级.强大的开源容器虚拟化平台,使用包含了工作流的虚拟化技术,帮助用户建立.并容器化一个应用. Docker Hub,提供的一个SaaS服务,用 ...
- logistic回归 c++ 实现
logistic回归是统计学习中经典的分类方法,他属于对数线性模型.本博文主要给出logistic的c++实现,具体理论请读者自行google. 本文用到的数据集来自于一个医学网站,具体出处不记得了( ...
- HTML初学者的三十条最佳
颜海镜 专注web前端,分享html,css,javascript等相关知识…… 给HTML初学者的三十条最佳实践 Nettuts +运营最困难的方面是为很多技能水平不同的用户提供服务.如果我们发布太 ...
- 在 Ubuntu 12.04 上通过 Tomcat 部署 Solr 4
http://www.oschina.net/question/12_71342 可行
- JavaScript插件——弹出框
(JavaScript插件——弹出框) 前言 阅读之前您也可以到Bootstrap3.0入门学习系列导航中进行查看http://www.cnblogs.com/aehyok/p/3404867.htm ...