↓ Skip to main content
  1. Posts/

hdoj 2436 Collision Detection

·827 words·2 mins
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

Collision Detection
#

**Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1207 Accepted Submission(s): 367 **

Problem Description

  In physical simulations, video games and computational geometry, collision detection involves algorithms for checking for collision, i.e. intersection, of two given objects. Collision detection algorithms are a basic component of 3D video games. Without them, characters could go through walls and other obstacles.

Here comes an interesting problem, given a ball and a cuboid, you need to detect whether they collide. We say that two objects collide if and only if they share at least one point.

Input

  The first line of input is the number of test cases.

Each test case contains two lines, the first line contains 24 integers X1, Y1, Z1, …, X8, Y8, Z8, representing the 8 vertexes of the cuboid. Vertexes are given in random order and you can make sure that all edges of the cuboid are parallel to coordinate axes; the second line contains 4 integers X,Y,Z,R representing the central point of the ball and its radius. All integers given are non-negative and will be less than 100000.

Output

  For each case output "Yes" Or "No" on a single line.

Sample Input

2 0 0 0 0 0 1 0 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 1 2 2 2 2 0 0 0 0 0 1 0 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 1 2 2 2 1

Sample Output

Yes No

Source

2008 Asia Chengdu Regional Contest Online

Recommend

lcy | We have carefully selected several similar problems for you: 2437 2429 2433 2435 2428

真是日了狗了……

读错题 WA 到死。

英文差的原因?

我以为长方体是空心的。

然后球是有可能在内部。

我说我怎么写的那么麻烦,又是判断点,又是判断边,又是判断面。

然后全推了重写……

又 WA 到死。

最后发现又是强制转换类型的问题。

如果变量是 int 类型,即使一开始赋值给 long long,在赋值之前的计算也会溢出。

所以不溢出的办法就是把 int 直接写成 long long 类型。

代码实现
 1/*************************************************************************
 2	> File Name: code/2015summer/#6/II.cpp
 3	> Author: 111qqz
 4	> Email: rkz2013@126.com
 5	> Created Time: 2015年08月01日 星期六 03时09分18秒
 6 ************************************************************************/
 7
 8#include<iostream>
 9#include<iomanip>
10#include<cstdio>
11#include<algorithm>
12#include<cmath>
13#include<cstring>
14#include<string>
15#include<map>
16#include<set>
17#include<queue>
18#include<vector>
19#include<stack>
20#define y0 abc111qqz
21#define y1 hust111qqz
22#define yn hez111qqz
23#define j1 cute111qqz
24#define tm crazy111qqz
25#define lr dying111qqz
26using namespace std;
27#define REP(i, n) for (int i=0;i<int(n);++i)
28typedef long long LL;
29typedef unsigned long long ULL;
30const int inf = 0x7fffffff;
31
32
33LL dis(LL x1,LL x2,LL y1,LL y2,LL z1,LL z2)
34{
35
36    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2);
37
38}
39int main()
40{
41    int T;                 //整体算法是寻找距离球最近的点,比较这个点到球心的距离和半径
42			    // 。。。判断了边+点+面还没A的我好傻逼啊。。。。。。。。sad
43			    // 卧槽,读错题了,长方体是实心的啊喂!怪不得我想的那么麻烦!
44    cin>>T;
45    while (T--)
46    {
47	LL tx,ty,tz;
48	LL x1 = inf;
49	LL x2 = -inf;
50	LL y1 = inf;
51	LL y2 = -inf;
52	LL z1 = inf;
53	LL z2 = -inf;
54	for ( int i = 1 ; i <= 8 ; i++ )
55	{
56
57	    scanf("%lld %lld %lld",&tx,&ty,&tz);
58	    x1 = min(tx,x1);
59	    x2 = max(tx,x2);
60	    y1 = min(ty,y1);
61	    y2 = max(ty,y2);
62	    z1 = min(tz,z1);
63	    z2 = max(tz,z2);
64	}
65	LL bx,by,bz,r;
66	    LL x,y,z;
67	scanf("%lld %lld %lld %lld",&bx,&by,&bz,&r);
68	x = bx;
69	y = by;
70	z = bz;
71	if (x>x2) x=x2;
72	if (x<x1) x=x1;
73	if (y>y2) y=y2;
74	if (y<y1) y=y1;
75	if (z>z2) z=z2;
76	if (z<z1) z=z1;
77	if (r*r>=dis(x,bx,y,by,z,bz))
78	{
79	    puts("Yes");
80	}
81	else
82	{
83	    puts("No");
84	}
85
86
87    }
88
89	return 0;
90}

Related

hdu 4082 I Hou Yi's secret (计算几何)

·1333 words·3 mins
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=83295#problem/I 最多18个点,选3个点,能够成的三角形不超过1000个,O(n2)暴力就可以。 思路就是枚举三个点点,对于每一个构成的三角形,把这个三角形的最小角和次小角存起来。 然后枚举三角形,判断是否有两个三角形的最小角和次小角分别对应相等。

hdu 5120 - Intersection

·665 words·2 mins
题意:求两个相等的圆环的相交的面积…. 简单计算几何+容斥原理? 扇形面积公式记错调了半天2333333333 这题不难…倒是从学长那里收获了几点关于代码规范的问题… 听说了学长在北京区域赛时把PI定义错了一位结果一直WA的教训…. 以后还是写acos(-1)吧 局部变量和全局变量因为【想怎么其变量名想得整个人都不好了】就起成了一样的…被学长给了差评。 哦,对!还有一个就是发现了cmath库里有一个奇葩的函数名叫y1.。。。。。。。 —————————————————————————————————————————————— 竟然CE了 提示 error:pow(int,int) is ambiguous 看来我对语言的掌握程度还是不行呀…..

hdu 5233 Gunner II (bc #42 B) (离散化)

·872 words·2 mins
Gunner II # **Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1433 Accepted Submission(s): 540 ** Problem Description Long long ago, there was a gunner whose name is Jack. He likes to go hunting very much. One day he go to the grove. There are n birds and n trees. The i-th bird stands on the top of the i-th tree. The trees stand in straight line from left to the right. Every tree has its height. Jack stands on the left side of the left most tree. When Jack shots a bullet in height H to the right, the nearest bird which stands in the tree with height H will falls.

bc #43(hdu 5265) pog loves szh II (单调性优化)

·624 words·2 mins
pog loves szh II # **Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2115 Accepted Submission(s): 609 ** Problem Description Pog and Szh are playing games.There is a sequence with n numbers, Pog will choose a number A from the sequence. Szh will choose an another number named B from the rest in the sequence. Then the score will be (A+B) mod p.They hope to get the largest score.And what is the largest score?