hdoj 3209 Jumping Hands

思路:模拟。以钟表中心建立直角坐标系,根据每根针权重计算出重心,确定长度,并根据当前时间确定每根针的角度,计算出相应的x,y坐标,这样每一秒的距离都计算出来了

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

const double PI = acos(-1.0);
int l1, l2, l3, m1, m2, m3;
int hh, mm, ss;
int st, ed;

struct Point {
    double x, y;
};

double getdis(Point a, Point b) {
    return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
}

Point getpoint(int t) {
    Point p, ph, pm, ps;
    double w = m1 + m2 +m3;
    double lh, lm, ls, ah, am, as;
    lh = l1*m1/w;
    lm = l2*m2/w;
    ls = l3*m3/w;
    ah = 2*PI*t/43200;
    am = 2*PI*t/3600;
    as = 2*PI*t/60;
    ph.x = sin(ah)*lh;
    ph.y = cos(ah)*lh;
    pm.x = sin(am)*lm;
    pm.y = cos(am)*lm;
    ps.x = sin(as)*ls;
    ps.y = cos(as)*ls;
    p.x = ph.x + pm.x + ps.x;
    p.y = ph.y + pm.y + ps.y;
    return p;
}

int main() {
    while (1) {
        scanf("%d", &l1);
        if (l1 == -1)
            break;
        scanf("%d %d %d %d %d", &l2, &l3, &m1, &m2, &m3);
        scanf("%d:%d:%d", &hh, &mm, &ss);
        st = hh*3600 + mm*60 + ss;
        scanf("%d:%d:%d", &hh, &mm, &ss);
        ed = hh*3600 + mm*60 + ss;
        Point p1, p2;
        p1 = getpoint(st);
        double ans = 0;
        int i;
        for (i = st+1; i <= ed; ++i) {
            p2 = getpoint(i);
            ans += getdis(p1, p2);
            p1 = p2;
        }
        printf("%.2lf\n", ans/2);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值