hdu 1006 Tick and Tick

Tick and Tick

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 19764    Accepted Submission(s):
5164

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

题解:直接就枚举就好了

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <algorithm>
 4 #include <string.h>
 5 #include <cmath>
 6 using namespace std;
 7 double D;
 8 double sum;
 9 struct node
10 {
11     double l,r;
12 };
13 node ans[3][2];
14 node solve(double a,double b)
15 {
16     node qu;
17     if(a>0)
18     {
19         qu.l=(D-b)/a;
20         qu.r=(360-D-b)/a;
21     }
22     else
23     {
24         qu.l=(360-D-b)/a;
25         qu.r=(D-b)/a;
26     }
27     if(qu.l<0) qu.l=0;
28     if(qu.r>60) qu.r=60;
29     if(qu.l>=qu.r) { qu.l=qu.r=0;}
30     return qu;
31 }
32 node mer_g(node a,node b)
33 {
34     node q;
35     q.l=max(a.l,b.l);
36     q.r=min(a.r,b.r);
37     if(q.l>q.r) q.l=q.r=0;
38     return q;
39 }
40 int main()
41 {
42     int h,m;
43     int i,j,k;
44     double a1,a2,a3,b1,b2,b3;
45     while(scanf("%lf",&D),D!=-1)
46     {
47         sum=0;
48         node qu;
49        for(h=0;h<12;h++)
50          for(m=0;m<60;m++)
51             {
52                b1=m*6;        a1=-5.9;
53                b2=30*h+(0.5-6)*m; a2=1.0/120-0.1;
54                b3=30*h+0.5*m; a3=1.0/120-6;
55                ans[0][0]=solve(a1,b1);ans[0][1]=solve(-a1,-b1);
56                ans[1][0]=solve(a2,b2);ans[1][1]=solve(-a2,-b2);
57                ans[2][0]=solve(a3,b3);ans[2][1]=solve(-a3,-b3);
58               for(i=0;i<2;i++)
59                for(j=0;j<2;j++)
60                 for(k=0;k<2;k++)
61                  {
62                    qu=mer_g(mer_g(ans[0][i],ans[1][j]),ans[2][k]);
63                    sum+=qu.r-qu.l;
64                  }
65             }
66       printf("%.3lf\n",sum*100/43200);
67     }
68     return 0;
69 }
时间: 2024-11-08 15:40:09

hdu 1006 Tick and Tick的相关文章

HDU 1006 Tick and Tick 解不等式解法

一开始思考的时候觉得好难的题目,因为感觉很多情况,不知道从何入手. 想通了就不难了. 可以转化为一个利用速度建立不等式,然后解不等式的问题. 建立速度,路程,时间的模型如下: /*************************************************************************** * * * 秒钟的速度s=6°/s,分针是1/10°/s,时针是1/120°/s * * 所以相对速度s_m=59/10°/s,s_h=719/120°/s,m_h=12

HDU 1006 Tick and Tick(时钟,分钟,秒钟角度问题)

传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1006 Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 22203    Accepted Submission(s): 5877 Problem Description The three hands of the

hdu 1006 Tick and Tick 有技巧的暴力

Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 16707    Accepted Submission(s): 4083 Problem Description The three hands of the clock are rotating every second and meeting each ot

HDU 1006 Tick and Tick 时钟指针问题

Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10194    Accepted Submission(s): 2859 Problem Description The three hands of the clock are rotating every second and meeting each ot

HDU1006 Tick and Tick【计算几何】

Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10770    Accepted Submission(s): 3008 Problem Description The three hands of the clock are rotating every second and meeting each o

Tick and Tick

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 th

HDU 1006 模拟

Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 20120    Accepted Submission(s): 5262 Problem Description The three hands of the clock are rotating every second and meeting each ot

HDU 1006 [Tick Tick]时钟问题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1006 题目大意:钟表有时.分.秒3根指针.当任意两根指针间夹角大于等于n°时,就说他们是happy的,问一天有百分之多少时间是happy的. 关键思想:两根指针两根指针地考虑,从重合到重合中有且仅有一段连续时间这两根指针是happy的.共有3种组合(时分.分秒.时秒),所以若以时间为横轴,夹角为纵轴,图像为三个连续三角形.另y大于等于n,得到的图像求符合区间的长度. 代码如下: //多个连续三角区域

HDU ACM 1006 Tick and Tick

题意:一个钟的三个指针在不停的转动,他们厌烦了这样,当他们互相的距离角度大于等于D时,他们会很开心,问一天之中他们happy的时间占总时间的百分比. 分析:只要找到某一分钟内,他们happy的时间,然后钟每过12个小时相当于43200秒复原一次.因此总时间就是43200秒,只要求出在这43200的happy时间,即可求出百分比.枚举12*60分钟,看一分钟内有多少秒是happy的时间,一分钟内解三个不等式可得到区间. 步骤: 1.列出指针(h:m:s)与度数(rh:rm:rs)之间的关系: 秒针