HDU1174(空间点到直线的距离,用叉积)
生活随笔
收集整理的這篇文章主要介紹了
HDU1174(空间点到直线的距离,用叉积)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
爆頭
Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2002????Accepted Submission(s): 868
?
Problem Description gameboy是一個(gè)CS高手,他最喜歡的就是扮演警察,手持M4爆土匪的頭。也許這里有人沒(méi)玩過(guò)CS,有必要介紹一下“爆頭”這個(gè)術(shù)語(yǔ):所謂爆頭,就是子彈直接命中對(duì)方的頭部,以秒殺敵人。現(xiàn)在用一個(gè)三維的直角坐標(biāo)系來(lái)描述游戲中的三維空間(水平面為xoy平面,z軸正方向是上方)。假設(shè)游戲中角色的頭是一個(gè)標(biāo)準(zhǔn)的球。告訴你土匪的身高,頭部半徑,所站位置的坐標(biāo);gameboy所控警察的身高,頭部半徑,所站位置的坐標(biāo),以及槍頭所指方向的單位向量。gameboy所控警察所握的是M4,搶瞄準(zhǔn)時(shí)槍膛中的子彈跟視線(xiàn)基本同線(xiàn),我們忽略它們的距離,就當(dāng)成同線(xiàn)。由于土匪手持AK47,所以他是很?chē)虖埖卣⒅?。而警察手持M4,正在瞄準(zhǔn),由于瞄準(zhǔn)時(shí)身體微彎,視線(xiàn)從頭心出發(fā),他頭部的實(shí)際高度比正立時(shí)低10%。
你的任務(wù)就是,計(jì)算gameboy在這一刻扣下扳機(jī),能否爆土匪的頭。注意:這里忽略子彈的直徑和重力作用,也就是說(shuō)子彈是無(wú)限小的,彈道是一條筆直的射線(xiàn),警察與土匪間沒(méi)有障礙物。并且只要子彈擦到頭部,哪怕是邊緣,也算爆頭。 Input 測(cè)試數(shù)據(jù)的第一行有一個(gè)正整數(shù)T,表示有T組測(cè)試數(shù)據(jù)。每組數(shù)據(jù)的第一行有五個(gè)實(shí)數(shù),h1,r1,x1,y1,z1,分別表示土匪的身高,頭部半徑以及所站的位置。第二行有八個(gè)實(shí)數(shù),h2,r2,x2,y2,z2,x3,y3,z3,分別表示警察的身高,頭部半徑,所站位置,以及槍頭所指方向的方向向量。 Output 每一組輸入數(shù)據(jù)對(duì)應(yīng)一行輸出。如果能爆土匪的頭,輸出"YES",否則輸出"NO"。
?
Sample Input 2 1.62 0.1 10.0 10.0?10.0 1.80 0.09 0.0 0.0 0.0 1.0 1.0 1.0 1.62 0.1 0.0 0.0 0.0 1.80 0.09 10.0 10.0 10.0 -1.0 -1.0 -1.0 Sample Output YES YES Author lwg /* * @Author: LinK * @Date: 2015-10-31 17:53:33 * @Last Modified by: LinK * @Last Modified time: 2015-10-31 18:12:22 */#include <map> #include <set> #include <cmath> #include <stack> #include <queue> #include <vector> #include <cstdio> #include <string> #include <utility> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define eps 1e-8 #define randin srand((unsigned int)time(NULL)) #define input freopen("input.txt","r",stdin) #define debug(s) cout << "s = " << s << endl; #define outstars cout << "*************" << endl; const double PI = acos(-1.0); const int inf = 0x3f3f3f3f; const int INF = 0x7fffffff; typedef long long ll;struct Line {double x, y, z;Line() {}Line(double _x, double _y, double _z) : x(_x), y(_y), z(_z) {} } line[10];double chaji(Line a,Line b) {double x1 = a.x;double y1 = a.y;double z1 = a.z;double x2 = b.x;double y2 = b.y;double z2 = b.z;double x = y1 * z2 - z1 * y2;double y = z1 * x2 - x1 * z2;double z = x1 * y2 - y1 * x2;return sqrt(x * x + y * y + z * z); } int main() {double h1, r1, x1, y1, z1;double h2, r2, x2, y2, z2, x3, y3, z3;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);line[1] = Line(x3, y3, z3);line[3] = Line(x1, y1, h1 - r1 / 2.0 + z1);line[4] = Line(x2, y2, h2 * 0.9 - r2 / 2.0 + z2);line[2] = Line(line[3].x - line[4].x, line[3].y - line[4].y, line[3].z - line[4].z);double tmp = chaji(line[1], line[2]);tmp /= sqrt(x3 * x3 + y3 * y3 + z3 * z3);if (tmp - r1 <= eps) printf("YES\n");else printf("NO\n"); }return 0; }?
轉(zhuǎn)載于:https://www.cnblogs.com/LinKArftc/p/4925923.html
總結(jié)
以上是生活随笔為你收集整理的HDU1174(空间点到直线的距离,用叉积)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Unity3d通用工具类之定时触发器
- 下一篇: 暑假集训-个人赛第六场