HDU_1006_Tick and Tick
2016-04-28 19:24
246 查看
Tick and Tick
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 16633 Accepted Submission(s): 4059
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
0
120
90
-1
[align=left]Sample Output[/align]
100.000
0.000
6.251
[align=left]Author[/align]
PAN, Minghao
[align=left]Source[/align]
ZJCPC2004
之前一秒一秒离散地模拟,一直wa。
最后看了题解,是看作连续来做。
由角速度求出相对角速度,再求出每两根针的周期(经过多久再次重合)。然后求12个小时内每两根针(3组)每个周期happy time的交集的和。
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; const double h_m=11.0/120,h_s=719.0/120,m_s=59.0/10; //相对角速度 const double Th_m=43200.0/11,Th_s=43200.0/719,Tm_s=3600.0/59; //周期 int main() { double d; while(scanf("%lf",&d)!=EOF&&d>=0) { ///d/h_m double sh_m=d/h_m; double eh_m=(360.0-d)/h_m; double sh_s=d/h_s; double eh_s=(360.0-d)/h_s; double sm_s=d/m_s; double em_s=(360.0-d)/m_s; double s1,e1,s2,e2,s3,e3,s4,e4,res=0; for(s1=sh_m,e1=eh_m;e1<=43200.000001;s1+=Th_m,e1+=Th_m) { for(s2=sh_s,e2=eh_s;e2<=43200.000001;s2+=Th_s,e2+=Th_s) { if(e1<=s2) break; if(e2<=s1) continue; for(s3=sm_s,e3=em_s;e3<=43200.000001;s3+=Tm_s,e3+=Tm_s) { if(s3>=e2||s3>=e1) break; if(e3<=s2||e3<=s1) continue; s4=max(s1,max(s2,s3)); e4=min(e1,min(e2,e3)); res+=(e4-s4); } } } printf("%.3lf\n",res/432); } return 0; }
相关文章推荐
- 《架构漫谈》心得体会
- oc开发笔记4 ios 声像图 波形和频谱
- leetcode的c++实现(一)
- c汇总
- leetcode---Palindrome Number
- Yii2 自定义Gii生成代码模板
- iOS工程引入ios-charts-master(cocoapod导入)
- 懵逼ZJOI2016Round2滚粗记
- 30-Container With Most Water-Leetcode
- 第8周项目1 工资类基本型
- 0428 团队项目合作2.0作业
- 架构漫谈读后感
- javascript设计模式 工厂模式
- cf535B. Tavas and SaDDas
- 分支限界法:最优装载问题
- eclipse快捷键的使用
- 密码学---PlayFair
- 【Java基础】Java中的char是否可以存储一个中文字符之理解字符字节以及编码集
- git总结
- 多个约束条件的查询