HDU 1006 TICk and TICK

来源:互联网 发布:openwrt ip mac绑定 编辑:程序博客网 时间:2024/06/07 11:35
                       

Tick and Tick

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


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
012090-1
 

Sample Output
100.0000.0006.251
 


  大意: 这里是说时针分针秒针相互之间的夹角, 在一天内的夹角只要是大于 D的 时刻那么就是 happytime 这里要计算一天happytime 的概率,要算的是happytime的次数除以总次数 就是happytime 的概率  思路肯定会想以哪个针为参照物呢,怎样确定各针走的角度呢, 回答是以秒针为参照 分别计算各针在 钟上的角度,然后做差那马就是夹角了( 有时候我会想要不要判断正负呢,其实不判断也没什么的)  再 其次就是统计在夹角范围外的次数 是多少除以总次数 为所求
下面是代码: 但是没有AC 但是我觉得思路是没问题的
<pre name="code" class="cpp">#include<iostream>#include<cstdio>#include<iomanip>using namespace std;double caculate(double a, double b){    double tmp = (a > b)?(a-b):(b-a);    if( tmp > 180)  tmp = 360 - tmp ;    return tmp;}int main(){//题目大意 时针分针, 秒针 只要三根针相互之间的夹角在大于D那么就是happytime 现在要求的就是happytime的概率    //以 最小的秒针的速度为基准     //秒针的角度  des = s*6 角速度为6 ;     //分针走的角度  dem =((s/60) + (s%60)/60)*6     //时针走的速度 deh = ((s/3600)*1.0 +(s%3600)/3600)*30     int total = 12*60*60;     int s ;     double deh , dem, des;     double D;     while(scanf("%lf", &D) != EOF)     {         if(D == -1) break ;         int cnt = 0;         for( s = 0 ; s < total ; s++)         {              int ss = s%60 ;              des = ss*6;              dem = (((s/60)%60)*1.0 + (s%60)/60.0)*6; //这里也是开始bug 意思是多少整分 再加上0.几分但是后面必须带上.0例如60.0              deh = ((s/3600)*1.0 + (s%3600)/3600.0)*30;              if(caculate(des, dem) < D || caculate(des, deh) < D || caculate(deh, dem) < D) continue;                cnt ++;         }         printf("%.3lf\n",cnt*1.0/(12*60*60.0)*100);     }     return 0;}


结果是WR 什么原因呢?
待续。。。。


0 0
原创粉丝点击