Tick and Tick------HDOJ杭州电(无法解释,直接看代码)
2015-06-10 19:23
381 查看
[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]
[align=left]Sample Output[/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
#include <iostream> #include <iomanip> using namespace std; #define vs 6. #define vm 1./double(10) #define vh 1./double(120) int main() { double D; double T[3]= {(360./(vm-vh)),(360./(vs-vm)),(360./(vs-vh))}; ///时分 分秒 时秒 的相对周期 while(cin>>D && D!=-1) { double HS[3]= {(D/360.)*T[0],(D/360.)*T[1],(D/360.)*T[2]}; ///存储每对针的開始Happy时间 double HE[3]= {(360.-D)/360.*T[0],((360.-D)/360.*T[1]),((360.-D)/360.*T[2])}; ///存储每对针的结束Happy时间 double happyTime=0.,nextHS=HS[0],nextHE=min(HE[1],HE[2]); while(HS[1]<43200-(D/360.)*T[0] && HS[2]<43200-(D/360.)*T[0]) { nextHS= max(HS[0],max(HS[1],HS[2])); nextHE= min(HE[0],min(HE[1],HE[2])); happyTime += (nextHE-nextHS)>0.?nextHE-nextHS:0.; for(int i=0; i<3; i++) { HS[i]+=(nextHE-HE[i]<0.?HE[i]-nextHE:nextHE-HE[i])<1e-15?T[i]:0.; HE[i]+=(nextHE-HE[i]<0.? HE[i]-nextHE:nextHE-HE[i])<1e-15?T[i]:0.; } } double result= happyTime/432.; cout<<setiosflags(ios::fixed)<<setprecision(3)<<result<<endl; } return 0; }
这个问题由特定牛的回答,门户:丹尼尔问题解决地址
相关文章推荐
- c++ ifsteam 多次读取文件的问题
- Kmeans聚类算法及其java实现
- Java 递归算法
- 360技术开发实习笔试题1-java
- java web学习路线2
- python爬虫解决百度贴吧登陆验证码问题
- 229_尚学堂_高淇_java300集最全视频教程_【GOF23设计模式】_简单工厂模式详解
- java.util.Date和java.sql.Date的区别及应用
- 360技术开发实习笔试题2-java
- JSON和JAVA的bean的相互转换
- 权重随机算法Java实现
- C#语言开发的WinForm简易计算器
- WinSock2编程之打造完整的SOCKET池
- [.net 面向对象编程基础] (18) 泛型
- Python 的stat 模块
- 用Python写了一个postgresql函数,感觉很爽
- 用Python写了一个postgresql函数,感觉很爽
- java web 开发学习路线1
- python:re.sub简要分析
- java poi 技术总结