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): 5214    Accepted Submission(s): 1402


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
 

 

Author
PAN, Minghao
 

 

Source
 

 

Recommend
JGShining

//基本是按这博客介绍的写法写的

http://blog.sina.com.cn/s/blog_81650692010138nr.html

//感觉这题真的好神奇+变态、解不等式

//还是这位哥写的好,用变量替换、省了很多代码

//要是我、知道思路后、就只有朴素的写法、然后自己都写的好烦、、、

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <cmath>
using namespace std;
double D;
double sum;
struct node
{
    double l,r;
};
node ans[3][2];
node solve(double a,double b)
{
    node qu;
    if(a>0)
    {
        qu.l=(D-b)/a;
        qu.r=(360-D-b)/a;
    }
    else
    {
        qu.l=(360-D-b)/a;
        qu.r=(D-b)/a;
    }
    if(qu.l<0) qu.l=0;
    if(qu.r>60) qu.r=60;
    if(qu.l>=qu.r) { qu.l=qu.r=0;}
    return qu;
}
node mer_g(node a,node b)
{
    node q;
    q.l=max(a.l,b.l);
    q.r=min(a.r,b.r);
    if(q.l>q.r) q.l=q.r=0;
    return q;
}
int main()
{
    int h,m;
    int i,j,k;
    double a1,a2,a3,b1,b2,b3;
    while(scanf("%lf",&D),D!=-1)
    {
        sum=0;
        node qu;
       for(h=0;h<12;h++)
         for(m=0;m<60;m++)
            {
               b1=m*6;        a1=-5.9;
               b2=30*h+(0.5-6)*m; a2=1.0/120-0.1;
               b3=30*h+0.5*m; a3=1.0/120-6;
               ans[0][0]=solve(a1,b1);ans[0][1]=solve(-a1,-b1);
               ans[1][0]=solve(a2,b2);ans[1][1]=solve(-a2,-b2);
               ans[2][0]=solve(a3,b3);ans[2][1]=solve(-a3,-b3);
              for(i=0;i<2;i++)
               for(j=0;j<2;j++)
                for(k=0;k<2;k++)
                 {
                   qu=mer_g(mer_g(ans[0][i],ans[1][j]),ans[2][k]);
                   sum+=qu.r-qu.l;
                 }
            }
      printf("%.3lf\n",sum*100/43200);
    }
    return 0;
}

posted on 2012-08-02 10:30  江财小子  阅读(2331)  评论(0编辑  收藏  举报