HDU 1006(时钟指针转角 **)
题意是说求出在一天中时针、分针、秒针之间距离均在 D 度以上的时间占比。
由于三针始终都在转动,所以要分别求出各个针之间的相对角速度,分别求出三针满足角度差的首次时间,再分别求出不满足角度差的最终时间,取这三个时间段的交集,也就是首次时间的最大值和最终时间的最小值之间的部分,要注意剪枝,去掉多余的部分,否则会超时的,
本人的代码也是借鉴了别人写出来的。代码如下:
#include <bits/stdc++.h>
using namespace std;
const double hm = 11.0/;//时针分针相对角速度hm = m - h = 360/3600 - 360/(12*3600) = 11/120
const double hs = 719.0/;//时针秒针相对角速度hs = s - h = 360/60 - 360/(12*3600) = 719/120
const double ms = 59.0/;//分针秒针相对角速度ms = s - m = 360/60 - 360/3600 = 59/10
const double thm = 43200.0/;//thm = 360/hm = 43200/11
const double ths = 43200.0/;//ths = 360/hs = 43200/719
const double tms = 3600.0/;//tms = 360/ms = 3600/59
const double eps = 1e-;
double max(double a,double b,double c)
{
if(a>b) return a>c?a:c;
return b>c?b:c;
}
double min(double a,double b,double c)
{
if(a<b) return a<c?a:c;
return b<c?b:c;
}
int main()
{
int deg;
double from1,from2,from3,to1,to2,to3,x1,x2,x3,y1,y2,y3,st,ed,ans;
while(scanf("%d",°))
{
if(deg==-) break;
from1 = deg/hm;
from2 = deg/hs;
from3 = deg/ms;
to1 = (-deg)/hm;
to2 = (-deg)/hs;
to3 = (-deg)/ms;
ans = 0.0;
for(x1 = from1, y1 = to1; y1 <= +eps; x1+=thm, y1+=thm)
for(x2 = from2, y2 = to2; y2 <= +eps; x2+=ths, y2+=ths)
{
if(x2>y1) break;
for(x3 = from3, y3 = to3; y3 <= +eps; x3+=tms, y3+=tms)
{
if(x3>y1 || x3>y2) break;
st = max(x1,x2,x3);
ed = min(y1,y2,y3);
if(st<ed) ans+=ed-st;
}
}
printf("%.3lf\n",ans*100.0/);//求出时间和的占比
}
return ;
}
HDU 1006(时钟指针转角 **)的更多相关文章
- HDU 1006 Tick and Tick 时钟指针问题
Tick and Tick Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1006 [Tick Tick]时钟问题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1006 题目大意:钟表有时.分.秒3根指针.当任意两根指针间夹角大于等于n°时,就说他们是happy的, ...
- HDU 1006 Tick and Tick(时钟,分钟,秒钟角度问题)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1006 Tick and Tick Time Limit: 2000/1000 MS (Java/Oth ...
- [ACM_模拟] HDU 1006 Tick and Tick [时钟间隔角度问题]
Problem Description The three hands of the clock are rotating every second and meeting each other ma ...
- HDU 5510---Bazinga(指针模拟)
题目链接 http://acm.hdu.edu.cn/search.php?action=listproblem Problem Description Ladies and gentlemen, p ...
- hdu 1006 Tick and Tick 有技巧的暴力
Tick and Tick Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1006 Tick and Tick 解不等式解法
一開始思考的时候认为好难的题目,由于感觉非常多情况.不知道从何入手. 想通了就不难了. 能够转化为一个利用速度建立不等式.然后解不等式的问题. 建立速度,路程,时间的模型例如以下: /******** ...
- HDU 1006 模拟
Tick and Tick Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1006 Digital Roots
Problem Description The digital root of a positive integer is found by summing the digits of the int ...
随机推荐
- day5 笔记
笔记 字符格式化输出: 占位符%s s=string 字符型%d d=dight 整数型%f f=float 浮点数 约等于小数 通过格式:%(str1,str2,str3)一一对应 数据运算 数据类 ...
- linux tar 解压命令
如果提示 common not find 先进行安装如下 wget http://www.rarsoft.com/rar/rarlinux-5.3.0.tar.gz tar -zxvf rarlinu ...
- opencv 图片缩放
import cv2 as cv import numpy as np # 图片缩放 img = cv.imread('../images/moon.jpg', flags=1) # flags=1读 ...
- 【Tsinsen A1039】【bzoj2638】黑白染色 (BFS树)
Descroption 原题链接 你有一个\(n*m\)的矩形,一开始所有格子都是白色,然后给出一个目标状态的矩形,有的地方是白色,有的地方是黑色,你每次可以选择一个连通块(四连通块,且不要求颜色一样 ...
- Hdoj 1248.寒冰王座 题解
Problem Description 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票(记住,只有一张钞票),为了防止自己在战斗中频繁的死掉,他决定给自己买一些道具,于是他来到了地精商店前. 死亡 ...
- 【bfs】1252 走迷宫
[题目描述] 一个迷宫由R行C列格子组成,有的格子里有障碍物,不能走:有的格子是空地,可以走. 给定一个迷宫,求从左上角走到右下角最少需要走多少步(数据保证一定能走到).只能在水平方向或垂直方向走,不 ...
- HDU6333 Harvest of Apples (杭电多校4B)
这莫队太强啦 先推公式S(n,m)表示从C(n, 0) 到 C(n, m)的总和 1.S(n, m) = S(n, m-1) + C(n, m) 这个直接可以转移得到 2.S(n, m) = ...
- Django 自定义过滤器
设定自定义过滤器之前要现在配置文件内把自己项目名在 INSTALLED_APPS 内导入 #已安装的django应用 INSTALLED_APPS = [ 'django.contrib.admin' ...
- c语言: 生成随机数
#include <time.h> srand((unsigned)time(NULL)); for(int i=0;i<10;i++) { //printf("%d\n& ...
- python基础之IO编程
读文件 with open('/path/to/file', 'r') as f: print(f.read()) 调用read()会一次性读取文件的全部内容,read()函数里面可以传入每次最多读取 ...