HDU1006
single line with a real number D between 0 and 120, inclusively. The input is
terminated with a D of -1.
time in a day that all of the hands are happy, accurate up to 3 decimal
places.
#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 p1;
if(a>)
{
p1.l=(D-b)/a;
p1.r=(-D-b)/a;
}
else
{
p1.l=(-D-b)/a;
p1.r=(D-b)/a;
}
if(p1.l<)
p1.l=;
if(p1.r>)
p1.r=;
if(p1.l>=p1.r)
p1.l=p1.r=;
return p1;
}
qujian compare(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=;
return p;
} double happytime(double h,double m)
{
double a,b;
int i,j,k;
qujian s[][],p2; //解方程D<=|hh-mm|<=360-D
a=1.0/120.0-0.1; //hh=30*h+m/2+s/120;
b=*h+m/2.0-*m;
s[][]=solve(a,b);
s[][]=solve(-a,-b); a=0.1-;
b=*m;
s[][]=solve(a,b);
s[][]=solve(-a,-b); a=1.0/-;
b=*h+m/2.0;
s[][]=solve(a,b);
s[][]=solve(-a,-b); double ans=;
for(i=; i<; i++)
{
for(j=; j<; j++)
for(k=; k<; k++)
{
p2=compare(compare(s[][i],s[][j]),s[][k]);
ans+=p2.r-p2.l;
}
}
return ans;
} int main()
{
while(scanf("%lf",&D))
{
if(D==-)
break;
double h,m,ans=;
for(h=; h<; h++)
{
for(m=; m<; m++)
ans+=happytime(h,m);
}
printf("%.3lf\n",ans*100.0/(**));
}
return ;
}
HDU1006的更多相关文章
- HDU--1006
题目介绍 Problem Description The three hands of the clock are rotating every second and meeting each oth ...
- hdu1006 Tick and Tick
原题链接 Tick and Tick 题意 计算时针.分针.秒针24小时之内三个指针之间相差大于等于n度一天内所占百分比. 思路 每隔12小时时针.分针.秒针全部指向0,那么只需要计算12小时内的百分 ...
- hdu1006 Tick and Tick (数学题 借鉴了大神的博客)
先缩短一半的时间:早上的12个小时和下午的12小时对时钟是一样的,因为时钟12小时与0小时的三针位置相同.接着就是了解到每次所有的针从有重合到再次有重合至多有一段连续的段符合三针分离度大于n.所以只要 ...
- 【hdu1006】解方程
http://acm.hdu.edu.cn/showproblem.php?pid=1006 这题坑了我好久,发现居然是一个除法变成了整除,TAT,所以建议在写较长的运算表达式的时候出现了除法尽量加个 ...
- hdu_1006 Tick and Tick(暴力模拟)
hdu1006 标签(空格分隔): 暴力枚举 好久没有打题了,退队了有好几个月了,从心底不依赖那个人了,原来以为的爱情戏原来都只是我的独角戏.之前的我有时候好希望有个人出现,告诉自己去哪里,做什么,哪 ...
随机推荐
- Testlink中分析结果的图表显示乱码
1.下载 tahoma.ttf 字体: 2.下载好后,我们将其放置到,testlink的安装目录的以下文件夹中: testlink/third_party/pchart/Fonts/ 接下来,修改配置 ...
- Android开发-API指南-数据存储
Storage Options 英文原文:http://developer.android.com/guide/topics/data/data-storage.html 采集日期:2015-02-0 ...
- 慕课网-安卓工程师初养成-3-9 Java中运算符的优先级
来源 http://www.imooc.com/code/1315 所谓优先级,就是在表达式中的运算顺序.Java 中常用的运算符的优先级如下表所示: 级别为 1 的优先级最高,级别 11 的优先级最 ...
- UITableView 详解 ()
(原本取至D了个L微信公众号) UITableView 详解 一.建立 UITableView DataTable = [[UITableView alloc] initWithFrame:CGRec ...
- css定义表格样式
table.gridtable { font-family: verdana,arial,sans-serif; font-size:11px; color:#333333; border-width ...
- Oracle笔记 六、PL/SQL简单语句块、变量定义
1.简单SQL语句,HellWorld示例 --输出信息 begin dbms_output.put_line('Oracle Hello World!'); end; 2.变量的定义.使用 --定义 ...
- Mybatis多条件查询
在Mybatis多条件查询中: 1.参数如果是多条件,则需要将将添加到Map集合中进行传入. 2.就是将其参数用有序数字进行代替. Mybatis单个String类型参数传递 mysql文如下,传入参 ...
- Android IOS WebRTC 音视频开发总结(三一)-- 自定义传输实现一对多
本文主要介绍基于Webrtc的多人视频会议的简单实现,文章来自博客园RTC.Blacker,支持原创,转载请说明出处. 前面提到基于开源框架的视频会议都存在诸多问题,所以我们通过重写WEBRTC传输模 ...
- 条款22 template method 模式
template method 模式,模板方法模式 其实他和C++模板没有关系. 前者是提供的为派生类设计者提供清晰指示的一种方法,这个事实表示"如何去实现基类所规定的契约" 基类 ...
- DirectDraw打造极速图形引擎(Alpha混合)
显然DirectDraw是Windows下写2D图形程序的最好选择,虽然Direct3D也可以写,但是没DirectDraw简单方便,特别对于初学者,一来就接触那么多函数和参数总不是件愉快的事,所以我 ...