HDU 1006 Tick and Tick 模拟

题意:就是问24小时中秒针,分针,时针的夹角两两大于d的时刻占总时刻的比重。
思路:模拟。我是求出秒针,分针,时针两两之间的速度,然后每次累加一个根据这个速度可以转 180 的区间,然后每次替换掉一个结束时刻最早的区间,直到有一个区间的开始时刻大于 246060s
坑点:时间不是连续的,不是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",&degree),degree+1) {
        input();
        solve();
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值