hdoj 2436 Collision Detection

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: [email protected]
 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
26 using namespace std;
27 #define REP(i, n) for (int i=0;i<int(n);++i)
28 typedef long long LL;
29 typedef unsigned long long ULL;
30 const int inf = 0x7fffffff;
31
32
33 LL 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 }
39 int 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 }
时间: 2024-10-07 12:32:32

hdoj 2436 Collision Detection的相关文章

Collision Detection

[Collision Detection] Collision Detection是Rigidbody中的一个属性.所以显然Collision Detection指定的类型只在Rigidbody之间才有用. 1.Collision Detection用来干什么? Used to prevent fast moving objects from passing through other objects without detecting collisions. 用于阻止快速移动的objects因

Chrome内置的断网Javascript 小游戏脚本示范

//示范面向对象 this 作用域 闭包 单例模式很好的示范 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 (function () { 5 'use strict'; 6 /** 7 * T

hidden node and exposed node problem

Exposed node problem In wireless networks, theexposed node problem occurs when a node is prevented from sending packets to other nodes because of a neighboring transmitter. Consider an example of 4 nodes labeled R1, S1, S2, and R2, where the two rece

碰撞器与触发器[Unity]

请看原帖,移步:Unity3d碰撞检测中碰撞器与触发器的区别 要产生碰撞必须为游戏对象添加刚体(Rigidbody)和碰撞器,刚体可以让物体在物理影响下运动.碰撞体是物理组件的一类,它要与刚体一起添加到游戏对象上才能触发碰撞.如果两个刚体相互撞在一起,除非两个对象有碰撞体时物理引擎才会计算碰撞,在物理模拟中,没有碰撞体的刚体会彼此相互穿过. 物体发生碰撞的必要条件: 两个物体都必须带有碰撞器(Collider),其中一个物体还必须带有Rigidbody刚体. 在unity3d中,能检测碰撞发生的

第二章 TCP/IP 基础知识

? TCP/IP ?transmission control protocol and ip internet protocol 是互联网众多通信协议中最为著名的. ? 2.2 TCP/IP 的标准化 2.2.2 TCP/IP 标准化精髓 TCP/IP 协议始终具有很强的实用性. 相比于TCP/IP ,OSI 之所以未能达到普及,主要原因在于未能尽早的制定可行性较强的协议.未能提出应对技术快速更新的协议以及没有能及时进行后期的改良的方案. 2.2.3 TCP/IP 规范 --RFC 那些需要标准

《Python编程快速上手 让繁琐工作自动化》pdf

<div id="article_content" class="article_content tracking-ad" data-mod="popu_307" data-dsm="post"> <p><br></p><p>下载地址:<a target="_blank" href="https://page74.ctfile.co

Bounding Volume Hierarchy BVH in OpenCASCADE

Bounding Volume Hierarchy BVH in OpenCASCADE [email protected] Abstract. Bounding Volume Hierarchy(BVH) organizes geometric objects in the tree based on spatial relationships. Each node in the tree contains an axis-aligned bounding box of all the obj

HashMap的工作原理

这是一节让你深入理解hash_map的介绍,如果你只是想囫囵吞枣,不想理解其原理,你倒是可以略过这一节,但我还是建议你看看,多了解一些没有坏处. hash_map基于hash table(哈希表).哈希表最大的优点,就是把数据的存储和查找消耗的时间大大降低,几乎可以看成是常数时间:而代价仅仅是消耗比较多的内存.然而在当前可利用内存越来越多的情况下,用空间换时间的做法是值得的.另外,编码比较容易也是它的特点之一. 其基本原理是:使用一个下标范围比较大的数组来存储元素.可以设计一个函数(哈希函数,也

CCNA题库之四

A network interface port has collision detection and carrier sensing enabled on a shared twisted pair network. From this statement, what is known about the network interface port? A. This is a 10Mb/s switch port. B. This is a 100Mbs switch port. C. T