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. C++的编译与连接

    编译器的任务是把我们人类通常能够读懂的文本形式的 C 语言文件转化成计算机能明白的目标文件.1.  预编译生成的仍然是.c文件1)把"include"的文件拷贝到要编译的源文件中. ...

  2. 数据库事务(Database Transaction)

    事务(Transaction)是访问并可能更新数据库中各种数据项的一个程序执行单元(unit).事务由事务开始(begin transaction)和事务结束(commit transaction或 ...

  3. 为什么要学习php

    前言: 有的人说java是世界上最伟大的编程语言,也有人说php是最伟大的编程语言,对于这个问题的争论,貌似一直都没有停息过. 前段时间也看过一份编程语言使用排行的调查资料,java当仁不让的保持着排 ...

  4. 安装运行Rovio

    https://github.com/ethz-asl/rovio下载代码,该存储库包含ROVIO(Robust Visual Inertial Odometry)框架. https://github ...

  5. oralce 存储过程、函数和触发器

    一.存储过程和存储函数 指存储在数据库中供所有用户程序调用的子程序叫存储过程.存储函数.   创建存储过程 用CREATE PROCEDURE命令建立存储过程. 语法: create [or repl ...

  6. 给dede添加栏目图片和栏目描述

    有的时候我们希望调用栏目时把栏目的图片和描述调出来,但dede好像没有提供栏目图片这个功能,而栏目的描述也是给meta:Description使用的,不是很方便.   所以我们需要自已给dede添加图 ...

  7. 源码安装php时出现Sorry, I cannot run apxs. Possible reasons follow:

    1.可能的原因是你没有安装perl > yum install perl > yum install httpd-devel 2.在你apache安装目录下的bin下找到apxs,并用vi ...

  8. Golang之go 命令用法

    Go 命令 Go 命令 Go语言自带有一套完整的命令操作工具,你可以通过在命令行中执行go来查看它们: 图1.3 Go命令显示详细的信息 这些命令对于我们平时编写的代码非常有用,接下来就让我们了解一些 ...

  9. Codeforces 689B. Mike and Shortcuts SPFA/搜索

    B. Mike and Shortcuts time limit per test: 3 seconds memory limit per test: 256 megabytes input: sta ...

  10. 80% UI 初学者走过的弯路,你走了几条?

    关于UI 对于初学UI设计的人而言,可能对UI具体是做什么,或者自己是否能顺利转行胜任这样的岗位存在一定的顾虑,今天我们就来重点说说UI是做什么的,以及学UI到有哪些需要避免的弯路. 1.UI设计是做 ...