关闭

HDU 1006区间取交

150人阅读 评论(0) 收藏 举报
分类:

题目链接:http://acm.split.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): 17570 Accepted Submission(s): 4350

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

#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct qujian
{
    double l,r;
};
double D;
qujian solve(double a,double b)//解方程 D<=a*x+b<=360-D ,并且和 [0,60] 取交集
{
    qujian p;
    if(a>0)
    {
        p.l=(D-b)/a;
        p.r=(360-D-b)/a;
    }
    else
    {
        p.l=(360-D-b)/a;
        p.r=(D-b)/a;
    }
    if(p.l<0)p.l=0;
    if(p.r>60)p.r=60;
    if(p.l>=p.r)  p.l=p.r=0;
    return p;
}
qujian jiao(qujian a,qujian b)
{
    qujian p;
    p.l=max(a.l,b.l);
    p.r=min(a.r,b.r);
    if(p.l>=p.r) p.l=p.r=0;
    return p;
}
/*
   hh=30*h+m/2+s/120;
   mm=6*m+s/10;
   ss=6*s;
   D<=|hh-mm|<=360-D;
   D<=|hh-ss|<=360-D;
   D<=|mm-ss|<=360-D;
   hh-mm=
*/
double happytime(int h,int m)//计算 h 时,m 分 满足题意的秒数
{
    double a,b;
    qujian s[3][2];
    qujian s1;

    //解方程 D<=|hh-mm|<=360-D
    //hh=30*h+m/2+s/120;
    //mm=6*m+s/10;
    a=1.0/120-0.1;
    b=30*h+m/2.0-6*m;
    s[0][0]=solve(a,b);
    s[0][1]=solve(-a,-b);

    //解方程  D<=|hh-ss|<=360-D
    //hh=30*h+m/2+s/120;
    //ss=6*s;
    a=1.0/120-6.0;
    b=30*h+m/2.0;
    s[1][0]=solve(a,b);
    s[1][1]=solve(-a,-b);

    //解方程  D<=|mm-ss|<=360-D
    //mm=6*m+s/10;
    //ss=6*s;
    a=0.1-6;
    b=6*m;
    s[2][0]=solve(a,b);
    s[2][1]=solve(-a,-b);

    double res=0;
    //六个区间,选三个取交集。
    //因为绝对值的式子得到的两个区间要并,而三个不同表达式的区间要交,故这样做。
    for(int i=0;i<2;i++)
      for(int j=0;j<2;j++)
         for(int k=0;k<2;k++)
         {
             s1=jiao(jiao(s[0][i],s[1][j]),s[2][k]);
             res+=s1.r-s1.l;
         }
    return res;
}

int main()
{
    while(scanf("%lf",&D))
    {
        if(D==-1) break;
        double res=0;
        int h,m;
        for(h=0;h<12;h++)
        {
            for(m=0;m<60;m++)
            {
                res+=happytime(h,m);
            }
        }
        printf("%.3lf\n",res*100.0/(60*60*12));
    }
    return 0;
}
0
0
查看评论

hdu 1006 Tick and Tick 数学+枚举

题意:时针,分针和秒针都厌倦了其余两针,只有在
  • a601025382s
  • a601025382s
  • 2014-07-15 14:30
  • 2329

HDU1006 Tick and Tick【计算几何】

题目大意:现在有一个普通时钟,有时针、分针、秒针,秒针不是一秒一秒间断走的,而是连 续走的。给你一个度数D(小于等于120°)。求:24小时中,三个指针超过这个度数的时间占所 有时间的百分比是多少。 思路:之前想的按每秒模拟一遍就可以了。没想到时间是连续的,而不是间隔的,参考了评论 区才知...
  • u011676797
  • u011676797
  • 2015-01-17 18:42
  • 1199

杭电ACM 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): 6204 ...
  • gubojun123
  • gubojun123
  • 2013-02-22 21:46
  • 5476

HDU_1006(指针夹角)

#include #include using namespace std; //给跪了...ORZ //const double w_h=1.0/120,w_m=1./10,w_s=6.0; //角速度 const double hm=11.0/120,hs=719.0/120,sm=59.0/...
  • qq122345615
  • qq122345615
  • 2013-10-29 11:08
  • 389

hdu1006 Tick and Tick (时钟问题)

Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14396...
  • yuyanggo
  • yuyanggo
  • 2015-05-16 09:24
  • 509

HDU1006

这题是我在HDU上第二次遇到的关于钟表的问题,都很坑人!         首先,我想大家都会在理解上出问题。其实吧,我觉得这题HDU的思想有问题,钟表是一秒一秒走的,哪有连续时间,表示不解!但题目要求,木有办法了。其次呢,结果要...
  • Lulipeng_cpp
  • Lulipeng_cpp
  • 2012-03-05 14:13
  • 5478

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): 16508 ...
  • liangzhaoyang1
  • liangzhaoyang1
  • 2016-04-14 10:58
  • 383

杭电ACM第1006题——Tick and Tick

#include #include /** *每秒钟秒针、分针、时针的角度 s=6°/s,m=1/10°/s,h=1/120°/s *每秒钟各针之间的相对速度 s_m=59/10°/s,s_h=719/120°/s,m_h=11/120...
  • miomiomiomio
  • miomiomiomio
  • 2017-03-22 12:10
  • 202

杭电ACM1006 Tick and Tick

Problem Description The three hands of the clock are rotating every second and meeting each other many times everyday. Finally, they get bored of thi...
  • JeCode
  • JeCode
  • 2015-11-30 19:42
  • 1363

杭电ACM题1006

杭电题1005 Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 16...
  • u010343650
  • u010343650
  • 2016-04-07 00:09
  • 787
    个人资料
    • 访问:11078次
    • 积分:352
    • 等级:
    • 排名:千里之外
    • 原创:19篇
    • 转载:38篇
    • 译文:0篇
    • 评论:0条
    文章存档