HDU1006 Tick and Tick【计算几何】
来源:互联网 发布:襄阳seo排名优化 编辑:程序博客网 时间:2024/05/21 22:25
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
Author
PAN, Minghao
Source
ZJCPC2004
题目大意:现在有一个普通时钟,有时针、分针、秒针,秒针不是一秒一秒间断走的,而是连
续走的。给你一个度数D(小于等于120°)。求:24小时中,三个指针超过这个度数的时间占所
有时间的百分比是多少。
思路:之前想的按每秒模拟一遍就可以了。没想到时间是连续的,而不是间隔的,参考了评论
区才知道怎么去做。顺便膜拜大神。。。
三个指针走的角速度:
秒针速度S = 6°/s,分针速度M = (1/10)°/s,时针速度H = (1/120)°/s
这三个指针两两之间的相对速度差为:
秒时相差S_H = (719/120)°/s,秒分相差S_M = (59/10)°/s,分时相差M_H = (120/11)°/s
相差一度需要的时间为
秒时相差SH = (120/719)s/度,秒分相差SM = (10/59)s/度,分时相差MH = (120/11)s/度
相差360°需要的时间为
秒时相差tSH = 43200.0/719,秒分相差tSM = 3600.0/59,分时相差tMH = 43200.0/11
三者之间都需要最少相差D°才能满足条件,设t为三个指针都满足条件的总时间,则t满足以下
条件:
N*SH + k1*tSH < t < tSH - N*SH +k1*tSH
N*SM + k2*tSM < t < tSM - N*SM + k2*tSM
N*MH + k3*tMH < t < tMH - N*MH + k3*tMH
先求出三指针两两之间第一次满足条件的时间和第一次不满足条件的时间。
在对两两指针之间满足条件的开始时间和结束时间进行遍历(三重循环),把所有满足条件的时
间累加起来就是所求满足条件的总时间。最后结果为:满足条件的总时间/43200*100。
#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>using namespace std;// 秒针速度 s = 6°/s 分针速度 m = 1/10° /s 时针 h = 1/120° /sconst double SH = 719.0/120, SM = 59.0/10, MH = 11.0/120;const double tSH = 43200.0/719, tSM = 3600.0/59, tMH = 43200.0/11;double Min(double a,double b,double c){ return min(a,min(b,c));}double Max(double a,double b,double c){ return max(a,max(b,c));}int main(){ double D; while(cin >> D && D!=-1) { double bSH,bSM,bMH,eSH,eSM,eMH,Begin,End,Sum = 0; bSH = D / SH; bSM = D / SM; bMH = D / MH; //计算第一次满足条件的时间(开始时间) eSH = (360-D)/SH; eSM = (360-D)/SM; eMH = (360-D)/MH; //计算第一次不满足条件的时间(结束时间) for(double b3 = bSH,e3 = eSH; e3 <= 43200.000001; b3+=tSH,e3+=tSH) { for(double b2 = bMH,e2 = eMH; e2 <= 43200.000001; b2+=tMH,e2+=tMH) { if(e2 < b3) //判断是否有交集 continue; if(b2 > e3) break; for(double b1 = bSM,e1 = eSM; e1 <= 43200.000001; b1+=tSM,e1+=tSM) { if(e1 < b2 || e1 < b3) continue; if(b1 > e2 || b1 > e3) break; Begin = Max(b1,b2,b3); //开始时间取最大,以满足全部要求 End = Min(e1,e2,e3); //结束时间取最小,以满足全部要求 Sum += (End-Begin); } } } printf("%.3lf\n",Sum/432); } return 0;}
- HDU1006 Tick and Tick【计算几何】
- hdu1006-Tick and Tick
- hdu1006 Tick and Tick
- Tick and Tick(hdu1006时间暴力)
- HDU1006---Tick and Tick HDU(135)
- hdu1006 Tick and Tick 区间交集
- hdu1006 Tick and Tick (时钟问题)
- Tick and Tick
- hdoj_1006 Tick and Tick
- hdu-Tick and Tick
- 1006 tick and tick
- 1006-Tick and Tick
- hdu1006--Tick and Tick--时钟角度问题+区间求并求交
- hdu1006 Tick and Tick (数学题 借鉴了大神的博客)
- HDU 1006 Tick and Tick
- HDOJ 1006 Tick and Tick
- HDU 1006 Tick and Tick
- hdu 1006 Tick and Tick
- linux 升级ssh6.7
- The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory的解决方法
- 50 Tips for Working with Unity全面的分析了Unity开发应注意的事
- 求一元二次方程的根
- PostgreSQL每日一贴-pg_stat_statements文档
- HDU1006 Tick and Tick【计算几何】
- iOS开发多线程篇—GCD介绍
- 企业级数据结构之-顺序表的连式存储
- 四舍五入
- linux学习之shell脚本 ------- 引用与运算符
- Unity3D------Transform和Input
- 仿网易下拉菜单,UC底部弹出菜单(带动画效果,讲解原理)
- 显示菱形
- Java NIO框架Netty教程(一) – Hello Netty