HDU 1006 TICk and TICK

Java 源码解读
Java 集合类源码,JUC 源码解读
wangxiaoming
                       

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
0 120 90 -1
 

Sample Output
100.000 0.000 6.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 什么原因呢?
待续。。。。


wangxiaoming CSDN认证博客专家 架构 Spring Boot Redis
博客是很好的总结和记录工具,如果有问题,来不及回复,关注微信公众号:程序员开发者社区,获取我的联系方式,向我提问,也可以给我发送邮件,联系 1275801617@qq.com
©️2020 CSDN 皮肤主题: Age of Ai 设计师: meimeiellie 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值