爆头题HDU - 1174

爆头题HDU - 1174

https://cn.vjudge.net/contest/288165#problem/G

题目概述
刚开始接触这个题虽然有点思路但总是做不出来, 想了一下又看了别人的博客才恍然大悟。
解题思路:
(两头中心所表示的向量设为s向量, 子弹方向向量为r)
这个题的关键是求一个夹角
然后通过夹角算出子弹轨迹与土匪头中心的距离d(这个d是头中心到子弹轨迹的距离, 点到直线的距离)。
最后, 这个距离d和土匪的头半径r1进行比较,看是否能爆头(▄︻┻┳═一…… ☆(>○<))
图

|a×s | = |a||s|sin(∅) ①
d = |s|sin(∅) ②
d = |a x s|/|a| ①和②合并
注释 : ① 通过向量积可求出sin
②可以求出d
然后只要d<=r1 就能爆头

#include <stdio.h>
#include <stdlib.h>
#include<math.h>
int main()
{
    double h1, r1, x1, y1, z1, hx1, hy1, hz1;//hx1, hy2...是土匪的头坐标
    double h2, r2, x2, y2, z2, hx2, hy2, hz2;//hx2......警察的头部坐标
    double x3, y3, z3;
    double ang1;//角的sin

    double d;//
    double a, b, c;

    int T;

    scanf("%d", &T);
    while(T--)
    {
        scanf("%lf %lf %lf %lf %lf", &h1, &r1, &x1, &y1, &z1);
        scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &h2, &r2, &x2, &y2, &z2, &x3, &y3, &z3);
        //求头的中心坐标
        hx1 = x1;
        hy1 = y1;
        hz1 = z1+h1-r1;
        hx2 = x2;
        hy2 = y2;
        hz2 = z2+h2*0.9-r2;

        a = hx1-hx2;
        b = hy1 - hy2;
        c = hz1 - hz2;
        double aa, bb, cc;
        aa = b*z3- c*y3;
        bb = c*x3-a*z3;
        cc = a*y3-b*x3;


        d = sqrt(aa*aa+bb*bb+cc*cc)/(sqrt(x3*x3+y3*y3+z3*z3));


        if(d<= r1)printf("YES\n");
        else printf("NO\n");




    }

    return 0;
}


posted @ 2019-03-15 19:49 Monkey1 阅读( ...) 评论( ...) 编辑 收藏

猜你喜欢

转载自blog.csdn.net/qq_43824791/article/details/88792902