您的位置:首页 > 其它

HDU 1006 Tick and Tick 模拟

2015-12-10 22:11 369 查看

题意:就是问24小时中秒针,分针,时针的夹角两两大于d的时刻占总时刻的比重。

思路:模拟。我是求出秒针,分针,时针两两之间的速度,然后每次累加一个根据这个速度可以转180。180^。的区间,然后每次替换掉一个结束时刻最早的区间,直到有一个区间的开始时刻大于24∗60∗60s24*60*60s。

坑点:时间不是连续的,不是1s,1s的走的,而是不停的在走,所以就不能计算出每一秒的相隔角度,再计算。

http://acm.hdu.edu.cn/showproblem.php?pid=1006

/*********************************************
Problem : HDU 1006
Author  : NMfloat
InkTime (c) NM . All Rights Reserved .
********************************************/

#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>

#define rep(i,a,b)  for(int i = a ; i <= b ; i ++)
#define rrep(i,a,b) for(int i = b ; i >= a ; i --)
#define repE(p,u) for(Edge * p = G[u].first ; p ; p = p -> next)
#define cls(a,x)   memset(a,x,sizeof(a))
#define eps 1e-8

using namespace std;

const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5;
const int MAXE = 2e5;

typedef long long LL;
typedef unsigned long long ULL;

int T,n,m,k;
double degree;

void input() {

}

double max_d(double a1,double a2,double a3) {
double max_deg = a1;
if(a2 > max_deg) max_deg = a2;
if(a3 > max_deg) max_deg = a3;
return max_deg;
}

double min_d(double a1,double a2,double a3) {
double min_deg = a1;
if(a2 < min_deg) min_deg = a2;
if(a3 < min_deg) min_deg = a3;
return min_deg;
}

void solve() {
double v12 = 6 - 1.0/10;
double v13 = 6 - 1.0/120;
double v23 = 1.0/10 - 1.0/120;
double base1,base2,base3,t1,t2,t3,t12,t13,t23,base12,base13,base23;
t1 = base1 = degree / v12 ; t2 = base2 = degree / v13; t3 = base3 = degree / v23;
t12 = 180 / v12; t13 = 180 / v13; t23 = 180 / v23;
base12 = t12 - t1 ; base13 = t13 - t2; base23 = t23 - t3;
double limit = 60 * 60 * 24;
int cnt1 = 1 , cnt2 = 1, cnt3 = 1;

double cro = 0;
double ans = 0;

while(1) {
//区间t1-t12 t2-t13 t3-t23
if(t1 > limit || t2 > limit || t3 > limit) break;
cro = min_d(t12,t13,t23) - max_d(t1,t2,t3);
if(cro < 0) cro = 0; ans += cro;
if(t12 <= t13 && t12 <= t23) {
if(cnt1 % 2) { t1 = t12 ; t12 += base12 ; }
else { t1 += 180 / v12 + base1; t12 = t1 + base12 ; }
cnt1 ++;
}
else if(t13 <= t12 && t13 <= t23) {
if(cnt2 % 2) { t2 = t13 ; t13 += base13 ; }
else { t2 += 180 / v13 + base2; t13 = t2 + base13 ; }
cnt2 ++;
}
else {
if(cnt3 % 2) { t3 = t23;  t23 += base23 ; }
else { t3 += 180 / v23 + base3; t23 = t3 + base23 ; }
cnt3 ++;
}
}
//printf("%d %d %d\n",cnt1,cnt2,cnt3);
printf("%.3lf\n",ans/limit*100);
}

int main(void) {
//freopen("a.in","r",stdin);
//scanf("%d",&T);
//while(T--) {
//while(~scanf("%d %d",&n,&m)) {
while(scanf("%lf",°ree),degree+1) {
input();
solve();
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: