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. ContextLoaderListener和Spring MVC中的DispatcherServlet学习

    DispatcherServlet介绍 DispatcherServlet是Spring前端控制器的实现,提供Spring Web MVC的集中访问点,并且负责职责的分派,与Spring IoC容器无 ...

  2. css3自定义placeholder字体颜色

    ::-webkit-input-placeholder{color:#f00;} ::-moz-placeholder{color:#f00;} :-moz-placeholder{color:#f0 ...

  3. 【校招面试 之 C/C++】第15题 C 回调函数

    转自:https://segmentfault.com/a/1190000008293902 做略微改动 什么是回调函数 我们先来看看百度百科是如何定义回调函数的: 回调函数就是一个通过函数指针调用的 ...

  4. iOS 代码调试

    僵尸对象导致crash(Thread 1:EXC_BAD_ACCESS(code=EXC_I386_GPFLT)),需要给位release模式,debug模式不打印内存地址 https://blog. ...

  5. [leetcode]29. Divide Two Integers 两整数相除

    Given two integers dividend and divisor, divide two integers without using multiplication, division ...

  6. windows 10 WSL 安装 Centos

    1. 打开 WSL,没啥好说的 使用管理员权限打开 powershell,执行 Enable-WindowsOptionalFeature -Online -FeatureName Microsoft ...

  7. TokuMX唯一索引不支持dropDups选项

    TokuMX v1.5.0的唯一索引(unique index)不支持dropDups选项, 如果源数据包含相同目标key的文档,将无法建立唯一索引. 问题场景: 从MongoDB到TokuMX的数据 ...

  8. PAT 1010 一元多项式求导 (25)(STL-map+思路)

    1010 一元多项式求导 (25)(25 分)提问 设计函数求一元多项式的导数.(注:x^n^(n为整数)的一阶导数为n*x^n-1^.) 输入格式:以指数递降方式输入多项式非零项系数和指数(绝对值均 ...

  9. POJ 2585.Window Pains 拓扑排序

    Window Pains Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1888   Accepted: 944 Descr ...

  10. [Jmeter]Xpath获取元素某个属性的值,以及获取最后一个元素某个属性的值

    XPath获取元素某个属性的值 XPath query:  clients/attribute::total XPath获取最后一个元素某个属性的值 XPath query:   /clients/c ...