博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Tick and Tick------HDOJ杭州电(无法解释,直接看代码)
阅读量:4478 次
发布时间:2019-06-08

本文共 1866 字,大约阅读时间需要 6 分钟。

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
#include 
#include
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; }

这个问题由特定牛的回答,门户:

转载于:https://www.cnblogs.com/zfyouxi/p/4567101.html

你可能感兴趣的文章
2013年终总结
查看>>
Start to study Introduction to Algorithms
查看>>
正则表达式
查看>>
Mysql的DATE_FORMAT()日期格式转换
查看>>
SparkStreaming入门及例子
查看>>
Web应用增加struts2支持
查看>>
java程序——凯撒加密
查看>>
Windows Store App之数据存储
查看>>
English class 82 The Importance of traveling
查看>>
python用递归函数解汉诺塔游戏
查看>>
Redis与Python交互
查看>>
Maximum-SubsequenceSum
查看>>
常用的一些shell变量
查看>>
Android无法删除项目+导入项目报错
查看>>
poj 2349(最小生成树应用)
查看>>
python接口自动化测试二十五:执行所有用例,并生成HTML测试报告
查看>>
c# 指定的存储区提供程序在配置中找不到,或者无效
查看>>
最简陋的python数据
查看>>
第一堂java web课
查看>>
操作系统简介
查看>>