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>
/*-----------------------------------------------
double取最大最小函数
*/
double max(double a,double b){
if(a>b)return a;
return b;
}
double min(double a,double b){
if(a>b)return b;
return a;
}//---------------------------------------------
/*
集合结构体
*/
struct set{
double a,double b;
};//集合区间的左右
double d;
/*---------------------------------------------
求d<=ax+b<360-d的解
*/
struct set sloveset(double a,double b){
struct set seta;
if(a>){
seta.a=(d-b)/a;
seta.b=(-d-b)/a;
}
else{
seta.b=(d-b)/a;
seta.a=(-d-b)/a;
}
if(seta.a<) seta.a=;
if(seta.b>) seta.b=;
if(seta.a>=seta.b) seta.a=seta.b=;//之前这句放到了if(seta.a<0)if(seta.b>60)前面了
return seta; //结果seta.b变成了负的怀疑是seta.b太大了冒了不知对错
}
/*---------------------------------------------
给2个集合求交集
*/
struct set intersection(struct set a,struct set b){
struct set p;
p.a=a.a>b.a ?a.a:b.a;
p.b=a.b<b.b ?a.b:b.b;
if(p.a>p.b) p.a=p.b=;
return p;
}//////////////////////////////////////////////////////////
int main(){
int h,m,i,j,k;
double a1,b1,a2,b2,a3,b3,time;
struct set answer[][],ensemble;
while(scanf("%lf",&d)&&d!=-){
time=;
for(h=;h<;h++){
for(m=;m<;m++){
b1=6.0*m;a1=-5.9;
b2=*h+0.5*m;a2=1.0/-6.0;
b3=*h+(0.5-)*m;a3=(1.0/)-0.1;
/*求3个绝对值不等式的解集 存到answer中answer[0][0] answer[0][1]要取并集剩下两个也是 */
answer[][]=sloveset(a1,b1); answer[][]=sloveset(-a1,-b1);
answer[][]=sloveset(a2,b2); answer[][]=sloveset(-a2,-b2);
answer[][]=sloveset(a3,b3); answer[][]=sloveset(-a3,-b3);
// 取过交集后,需要将3个式子的结果取并集 所以采用下面的方法
for(i=;i<;i++){
for(j=;j<;j++){
for(k=;k<;k++){
ensemble=intersection(intersection(answer[][i],answer[][j]),answer[][k]);
time+=ensemble.b-ensemble.a;
}
}
}
}
}
time=time*100.0/(*);
printf("%.3lf\n",time);
}
return ;
}
 

[ACM_模拟] HDU 1006 Tick and Tick [时钟间隔角度问题]的更多相关文章

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

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1006 Tick and Tick Time Limit: 2000/1000 MS (Java/Oth ...

  2. HDU 1006 Tick and Tick 时钟指针问题

    Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  3. hdu 1006 Tick and Tick 有技巧的暴力

    Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  4. hdu 1006 Tick and Tick

    Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  5. HDU 1006 模拟

    Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  6. hdu1006 Tick and Tick

    原题链接 Tick and Tick 题意 计算时针.分针.秒针24小时之内三个指针之间相差大于等于n度一天内所占百分比. 思路 每隔12小时时针.分针.秒针全部指向0,那么只需要计算12小时内的百分 ...

  7. HDU 1006 [Tick Tick]时钟问题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1006 题目大意:钟表有时.分.秒3根指针.当任意两根指针间夹角大于等于n°时,就说他们是happy的, ...

  8. HDU 1006 Tick and Tick 解不等式解法

    一開始思考的时候认为好难的题目,由于感觉非常多情况.不知道从何入手. 想通了就不难了. 能够转化为一个利用速度建立不等式.然后解不等式的问题. 建立速度,路程,时间的模型例如以下: /******** ...

  9. 1006 Tick and Tick

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1006 题意: 24小时中,三个指针之间超过某个度数的时间占所有时间的百分比是多少. 思路:主要是物理和数学 ...

随机推荐

  1. scanf与printf

    scanf格式控制的完整格式: %     *     m     l或h     格式字符 ①格式字符与printf函数中的使用方式相同,以%d.%o.%x.%c.%s.%f.%e,无%u格式.%g ...

  2. 56. Merge Intervals (Array; Sort)

    Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...

  3. 转)安装svn服务器

    以下转载自:http://www.linuxidc.com/Linux/2015-01/111956.htm 安装 安装软件包: sudo apt-get install subversion 配置 ...

  4. python的进程间的数据交互

    #先来看下如何实现多进程 # multiprocessing 这个是python的多进程的模块,我们会用到这个模块的很多方法 from multiprocessing import Process i ...

  5. php iframe 上传文件

    我们通过动态的创建iframe,修改form的target,来实现无跳转的文件上传.   具体的实现步骤 1.捕捉表单提交事件 2.创建一个iframe 3.修改表单的target,指向iframe ...

  6. Paxos Made Simple

    Paxos一致性算法——分布式系统中的经典算法,论文本身也有一段有趣的故事.一致性问题是分布式系统的根本问题之一,在论文中,作者一步步的加强最初一致性问题(2.1节提出的问题)的约束条件,最终导出了一 ...

  7. 演示Spring框架的JDBC模板的简单操作

    1. 步骤一:创建数据库的表结构 create database spring_day03; use spring_day03; create table t_account( id int prim ...

  8. iOS.Compiler

    1. 在Xcode4.6下创建的工程, 在Xcode5下build&run, 然后提示以下error. 难不成要在Xcode5下重新创建工程? Xcode cannot run using t ...

  9. htons、htonl与字节序大小端

    判断字节序大小端code #include <stdio.h> int main() { ) == ) printf("big endian\n"); else pri ...

  10. toArray()