acm--1006
//用角速度考虑解决问题
#include <cstdio>
#include <math.h>
#include <iostream>
#include <algorithm>
#define V_SEC 6.0 //秒针角速度
#define V_MIN 0.1 //分针角速度
#define V_HOU 1.0/120 //时针角速度
#define A_SEC s*6 //秒针角度
#define A_MIN m*6+s*0.1 //分针角度
#define A_HOU h*30+m*0.5+s/120.0 //时针角度
using namespace std;
struct interval { //区间
double l; //left
double r; //right
};
double Angle; //角度
int s=0; //秒数
interval solve(double v,double a) { //解方程
//Angle<=v*t+a<=360-Angle;,并且和[0,60]取交集
interval p;
if(v>0) {
p.l=(Angle-a)/v;
p.r=(360-Angle-a)/v;
} else {
p.l=(360-Angle-a)/v;
p.r=(Angle-a)/v;
}
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;
}
interval jiao(interval a,interval b) {
interval 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;
}
double happytime(int h,int m) { //计算h时m分 满足题意的秒数
double v_diff;//速度差
double a_diff;//角度差
interval s0[3][2];
interval s1;
/*解方程 Angle<=|hh-mm|<=360-Angle*/
v_diff=V_HOU-V_MIN;
a_diff=A_HOU-A_MIN;//时针分针夹角
s0[0][0]=solve( v_diff, a_diff);
s0[0][1]=solve(-v_diff,-a_diff);
/*解方程 Angle<=|hh-ss|<=360-Angle*/
v_diff=V_HOU-V_SEC;
a_diff=A_HOU-A_SEC;//时针秒针夹角
s0[1][0]=solve( v_diff, a_diff);
s0[1][1]=solve(-v_diff,-a_diff);
/*解方程 Angle<=|mm-ss|<=360-Angle*/
v_diff=V_MIN-V_SEC;
a_diff=A_MIN-A_SEC;//分针秒针夹角
s0[2][0]=solve( v_diff, a_diff);
s0[2][1]=solve(-v_diff,-a_diff);
/*
六个区间,选三个取交集
因为绝对值的式子得到的两个区间要并,而三个不同表达式
的区间要交,故这样做
*/
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(s0[0][i],s0[1][j]),s0[2][k]);
res+=s1.r-s1.l;
}
return res;
}
int main() {
int h,m;
while(scanf("%lf",&Angle)) {
if(Angle==-1)break;
double res=0;
for(h=0; h<12; h++)
for(m=0; m<60; m++)
res+=happytime(h,m);
printf("%.3lf\n",res*100.0/43200);
}
}
//没有找到恰当的方法解决问题,思考角度不够
最新文章
- java笔记--理解java类加载器以及ClassLoader类
- JS魔法堂:jQuery.Deferred(jQuery1.5-2.1)源码剖析
- Windows Store App 应用程序安装目录
- iBeacon
- Codeforces Round #232 (Div. 1)
- [Windows] php开发工具,zendstudio13使用方法补丁
- 不允许从数据类型 nvarchar 到 varbinary 的隐式转换
- 使用FastJson进行对象和JSON转换属性命名规则为下划线和驼峰的问题
- Django 分页组件替换自定义分页
- spring学习(三) ———— spring事务操作
- Window对象属性
- curl 抓取图片
- ISE14.7兼容性问题集锦https://www.cnblogs.com/ninghechuan/p/7241371.html
- 如何打开google,facebok等网站
- 单引号、双引号、int和char
- 【slenium专题】Webdriver同步设置
- Redis学习四:解析配置文件 redis.conf
- 学习使用资源文件[11] - DLL 中的资源文件
- JPA error org.hibernate.AnnotationException: No identifier specified for entity
- Bootstrap 按钮下拉菜单