您的位置:首页 > 其它

杭电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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: