HDU 1006 [Tick Tick]时钟问题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1006
题目大意:钟表有时、分、秒3根指针。当任意两根指针间夹角大于等于n°时,就说他们是happy的,问一天有百分之多少时间是happy的。
关键思想:两根指针两根指针地考虑,从重合到重合中有且仅有一段连续时间这两根指针是happy的。共有3种组合(时分、分秒、时秒),所以若以时间为横轴,夹角为纵轴,图像为三个连续三角形。另y大于等于n,得到的图像求符合区间的长度。
代码如下:
//多个连续三角区域求符合要求部分的区间长度
#include <iostream>
using namespace std; const double sv=6.00, mv=0.10, hv=1./120;
const double m_s=sv-mv, h_m=mv-hv, h_s=sv-hv; // 时分、时秒、分秒3组相对速度 int main(){
double sum=0;
double n;
while(cin>>n&&n!=-1){
sum=0;
double bms=n/m_s,ems=(360-n)/m_s,tms=360./m_s; //时分、时秒、分秒3组起始时间和终止时间以及周期
double bhm=n/h_m,ehm=(360-n)/h_m,thm=360./h_m;
double bhs=n/h_s,ehs=(360-n)/h_s,ths=360./h_s;
//12小时足矣 。.000001是为了防止漏跑一次。若除去会导致输入为0时结果不是100.
for(double a1=bhm,a2=ehm;a2<=43200.000001;a1+=thm,a2+=thm){
for(double b1=bms,b2=ems;b2<=43200.000001;b1+=tms,b2+=tms){
if(b2<a1)continue; //优化,否则TLE
if(b1>a2)break;
for(double c1=bhs,c2=ehs;c2<=43200.000001;c1+=ths,c2+=ths){
if(c2<a1 || c2<b1)continue;
if(c1>a2 || c1>b2)break;
sum+=
min(min(a2,b2),c2)-max(max(a1,b1),c1);//找三组都happy的时间,即"最晚始"在"最早终"之前的时间段。
}
}
}
printf("%.3lf\n",sum/432);
}
return 0;
}
HDU 1006 [Tick Tick]时钟问题的更多相关文章
- 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 时钟指针问题
Tick and Tick Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- [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 解不等式解法
一開始思考的时候认为好难的题目,由于感觉非常多情况.不知道从何入手. 想通了就不难了. 能够转化为一个利用速度建立不等式.然后解不等式的问题. 建立速度,路程,时间的模型例如以下: /******** ...
- HDU 1006(时钟指针转角 **)
题意是说求出在一天中时针.分针.秒针之间距离均在 D 度以上的时间占比. 由于三针始终都在转动,所以要分别求出各个针之间的相对角速度,分别求出三针满足角度差的首次时间,再分别求出不满足角度差的最终时间 ...
- HDU 1006 模拟
Tick and Tick Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1006 Digital Roots
Problem Description The digital root of a positive integer is found by summing the digits of the int ...
随机推荐
- winutils spark windows installation
http://stackoverflow.com/questions/37305001/winutils-spark-windows-installation
- How to get HTML code of a WebElement in Selenium
http://stackoverflow.com/questions/32234205/how-to-get-html-code-of-a-webelement-in-selenium WebElem ...
- expect ------提供用户名和密码的SSH自动登录脚本
使用VPN,每次都要在Terminal上重复输入命令: ssh -D port user@host 出来密码提示符后,把复杂的密码拷贝下来,然后粘贴到Terminal,敲回车... 终于忍受不了这样的 ...
- Quick Cocos2dx Http通讯 JSON
参考: 1 http://stackoverflow.com/questions/5975952/how-to-extract-http-message-body-in-basehttprequest ...
- 3505: [Cqoi2014]数三角形
3505: [Cqoi2014]数三角形 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1324 Solved: 807[Submit][Statu ...
- Android学习笔记--处理UI事件
Handling UI Events 在Android里, 有不只一种方式可以截获用户与你的应用程序交互的事件. 在你的界面上处理事件时,你需要捕获用户与某个View实例交互时所产生的事件.View类 ...
- ServiceStack.Redis 使用链接池方法
PooledRedisClientManager 1.RedisManage.cs public static class RedisManager { private static PooledRe ...
- arcgis_server_address_note
arcgis server api下载地址 https://developers.arcgis.com/downloads/ 先前版本的帮助 http://resources.arcgis.com/z ...
- 升级R版本后,更新Package
升级R版本后,若重新安装所有的package将非常麻烦,可以尝试运行一下程序: 1)在旧版本中的R中运行 #--run in the old version of R setwd("C:/T ...
- centos7.0之Lnmp和Lamp
首先配置防火墙 CentOS 7.0默认使用的是firewall作为防火墙 1.关闭firewall: systemctl stop firewalld.service #停止firewall sys ...