杭电ACM OJ 1006 Tick and Tick 厌倦时钟 其实就是简单的数学题
2017-11-10 17:54
288 查看
Tick and Tick
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 20152 Accepted Submission(s): 5269
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
翻译:给定一个角度,比如50度,求一天中时钟的3根指针(秒,分,时)都大于这个角度所占的时间
其实就是简单的数学题,这里只是粗略的用秒作为了最小单位,没有很精确;如果想又精确又在规定时间内可以算出来,可能得换种思路
public class TickTick { static Double d; public static void main(final String[] args) throws Exception { initData(); double result = calculate(d); System.out.println(result); } private static void initData() { d = 90.0; } private static double calculate(double d) { int count = 0; double sD = 0.0; double mD = 0.0; double hD = 0.0; for (int i = 0; i < 43200; i++) { sD = (i % 60) * 6; mD = ((double) (i % 3600)) / 10; hD = ((double) i) / 240; double dif1 = Math.abs(sD - mD); double dif2 = Math.abs(sD - hD); double dif3 = Math.abs(mD - hD); if (dif1 > 180) { dif1 = 360 - dif1; } if (dif2 > 180) { dif2 = 360 - dif2; } if (dif3 > 180) { dif3 = 360 - dif3; } if (dif1 >= d && dif2 >= d && dif3 >= d) { count++; } } return ((double) count) / 43200; } }
相关文章推荐
- 杭电ACM OJ 1008 Elevator 其实就是简单的加减法 有点水
- 杭电1006 Tick and Tick
- hdoj1006 Tick and Tick(数学问题,解不等式,求并集)
- hdu 1006 Tick and Tick 模拟时钟注意时间连续性!
- 杭电OJ——1006 Tick and Tick
- HDU-1006 Tick and Tick(模拟 + 区间交集 + 数学)
- 杭电ACM HDU 1006 Tick and Tick
- 杭电oj 1006 Tick and Tick
- hdu 1006 Tick and Tick 数学+枚举
- [ACM_模拟] HDU 1006 Tick and Tick [时钟间隔角度问题]
- 杭电oj 1006 Tick and Tick
- HDU 1006 Tick and Tick 时钟指针问题
- hdu 1006 Tick and Tick 时钟问题
- HDU 1006 Tick and Tick
- hdu 1006 Tick and Tick (解不等式方程)
- 有一道十分简单的数学题,但是我就是没想出来,不得以发在首页求助
- 杭电ACM OJ 1017 A Mathematical Curiosity 题很简单,就是题目意思太让人费解了!
- 51Nod-1006-Tick and Tick
- 杭电ACM OJ 1026 Ignatius and the Princess I DFS+BFS
- 【PAT】A1006. Sign In and Sign Out(简单字符串处理)