Ultimate Weapon
Time Limit: 2000MS   Memory Limit: 131072K
Total Submissions: 2430   Accepted: 1173

Description

In year 2008 of the Cosmic Calendar, the Aliens send a huge armada towards the Earth seeking after conquest. The humans now depend on their ultimate weapon to retain their last hope of survival. The weapon, while capable of creating a continuous, closed and convex lethal region in the space and annihilating everything enclosed within, unfortunately exhausts upon each launch a tremendous amount of energy which is proportional to the surface area of the lethal region.

Given the positions of all battleships in the Aliens' armada, your task is to calculate the minimum amount of energy required to destroy the armada with a single launch of the ultimate weapon. You need to report the surface area of the lethal region only.

Input

The first line contains one number N -- the number of battleships.(1 ≤ N ≤ 500) 
Following N lines each contains three integers presenting the position of one battleship.

Output

The minimal area rounded to three decimal places.

Sample Input

4
0 0 0
4 0 0
2 3 0
1 1 2

Sample Output

19.137

Hint

There are no four coplaner battleships.

Source

 
三维凸包裸题,求这些点组成的凸包的表面积,数据最大为500,用增量算法,且由于只求表面积,可以不用合并同一平面的三角形。
 
 #include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
const int N = ;
const double eps = 1e-;
typedef struct point3 {
double x, y, z;
point3() { }
point3(double a, double b, double c) :x(a), y(b), z(c) { }
point3 operator -(const point3 &b)const { //返回减去后的新点
return point3(x - b.x, y - b.y, z - b.z);
}
point3 operator +(const point3 &b)const { //返回加上后的新点
return point3(x + b.x, y + b.y, z + b.z);
}
//数乘计算
point3 operator *(const double &k)const { //返回相乘后的新点
return point3(x * k, y * k, z*k);
}
point3 operator /(const double &k)const { //返回相除后的新点
return point3(x / k, y / k, z / k);
}
double operator *(const point3 &b)const { //点乘
return (x*b.x + y*b.y + z*b.z);
}
point3 operator ^(const point3 &p) const { //叉积
return point3(y*p.z - p.y*z, z*p.x - x*p.z, x*p.y - y*p.x);
}
double vlen()const { //向量的模
return sqrt(x*x + y*y + z*z);
}
}point3;
struct fac {
int a, b, c;//凸包一个面上的三个点的编号
bool ok; //该面是否是最终凸包中的面
};
struct T3dhull {
int n; //初始点数
point3 ply[N]; //初始点
int trianglecnt; //凸包上三角形数
fac tri[N]; //凸包三角形可证明被创建的面不会超过6N
int vis[N][N]; //点i到点j是属于哪个面
double dist(point3 a) { return sqrt(a.x*a.x + a.y*a.y + a.z*a.z); } //两点长度
double area(point3 a, point3 b, point3 c){return dist((b - a) ^ (c - a));} //三角形面积*2 //返回四面体有向体积*6
//在储存面时,保证面的法线方向朝向凸包外部,如果在某一平面和点p所组成的四面体的有向体积为正,则p点在凸包外部,并且此点可以被p点看见。
double volume(point3 a, point3 b, point3 c, point3 d){
return ((b - a) ^ (c - a))* (d - a);
}
double ptoplane(point3 &p, fac &f){ //点到平面距离,体积法
point3 m = ply[f.b] - ply[f.a], n = ply[f.c] - ply[f.a], t = p - ply[f.a];
return (m^n) * t;
}
void deal(int p, int a, int b) {
int f = vis[a][b];
fac add;
if (tri[f].ok)
{
if ((ptoplane(ply[p], tri[f])) > eps)
dfs(p, f);
else
{
add.a = b, add.b = a, add.c = p, add.ok = ;
vis[p][b] = vis[a][p] = vis[b][a] = trianglecnt;
tri[trianglecnt++] = add;
}
}
}
void dfs(int p, int cnt) {//维护凸包,如果点p在凸包外侧则更新凸包
tri[cnt].ok = ;
deal(p, tri[cnt].b, tri[cnt].a);
deal(p, tri[cnt].c, tri[cnt].b);
deal(p, tri[cnt].a, tri[cnt].c);
}
bool same(int s, int e) {
point3 a = ply[tri[s].a], b = ply[tri[s].b], c = ply[tri[s].c];
return fabs(volume(a, b, c, ply[tri[e].a])) < eps
&& fabs(volume(a, b, c, ply[tri[e].b])) < eps
&& fabs(volume(a, b, c, ply[tri[e].c])) < eps;
}
void construct()//构造凸包
{
int i, j;
trianglecnt = ;
if (n<) return;
bool tmp = true;
for (i = ; i < n; i++) //前两点不共点
{
if ((dist(ply[] - ply[i])) > eps)
{
swap(ply[], ply[i]);
tmp = false;
break;
}
}
if (tmp)return;
tmp = true;
for (i = ; i < n; i++) //前三点不共线
{
if ((dist((ply[] - ply[]) ^ (ply[] - ply[i]))) > eps)
{
swap(ply[], ply[i]);
tmp = false;
break;
}
}
if (tmp) return;
tmp = true;
for (i = ; i < n; i++) //前四点不共面
{
if (fabs(((ply[] - ply[]) ^ (ply[] - ply[]))* (ply[] - ply[i]))>eps)
{
swap(ply[], ply[i]);
tmp = false;
break;
}
}
if (tmp)return;
fac add;
for (i = ; i < ; i++) //构建初始四面体
{
add.a = (i + ) % , add.b = (i + ) % , add.c = (i + ) % , add.ok = ;
if ((ptoplane(ply[i], add))>)
swap(add.b, add.c);
vis[add.a][add.b] = vis[add.b][add.c] = vis[add.c][add.a] = trianglecnt;
tri[trianglecnt++] = add;
}
for (i = ; i < n; i++) //构建更新凸包
{
for (j = ; j < trianglecnt; j++)
{
if (tri[j].ok && (ptoplane(ply[i], tri[j])) > eps)
{
dfs(i, j); break;
}
}
}
int cnt = trianglecnt;
trianglecnt = ;
for (i = ; i < cnt; i++)
{
if (tri[i].ok)
tri[trianglecnt++] = tri[i];
}
}
double area() //表面积
{
double ret = ;
for (int i = ; i < trianglecnt; i++)
ret += area(ply[tri[i].a], ply[tri[i].b], ply[tri[i].c]);
return ret / 2.0;
}
double volume()
{
point3 p(, , );
double ret = ;
for (int i = ; i < trianglecnt; i++)
ret += volume(p, ply[tri[i].a], ply[tri[i].b], ply[tri[i].c]);
return fabs(ret / );
}
}hull; int main() {
while (~scanf("%d", &hull.n)) {
int i;
for (i = ; i < hull.n; i++)
scanf("%lf %lf %lf", &hull.ply[i].x, &hull.ply[i].y, &hull.ply[i].z);
hull.construct();
printf("%.3lf\n", hull.area());
}
return ;
}

POJ 3528--Ultimate Weapon(三维凸包)的更多相关文章

  1. poj 3528 Ultimate Weapon (3D Convex Hull)

    3528 -- Ultimate Weapon 一道三维凸包的题目,题目要求求出三维凸包的表面积.看懂了网上的三维凸包的代码以后,自己写的代码,跟网上的模板有所不同.调了一个晚上,结果发现错的只是数组 ...

  2. POJ 3528 求三维凸包表面积

    也是用模板直接套的题目诶 //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include < ...

  3. POJ 2225 / ZOJ 1438 / UVA 1438 Asteroids --三维凸包,求多面体重心

    题意: 两个凸多面体,可以任意摆放,最多贴着,问他们重心的最短距离. 解法: 由于给出的是凸多面体,先构出两个三维凸包,再求其重心,求重心仿照求三角形重心的方式,然后再求两个多面体的重心到每个多面体的 ...

  4. 三维凸包求其表面积(POJ3528)

    Ultimate Weapon Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 2074   Accepted: 989 D ...

  5. hdu4273Rescue(三维凸包重心)

    链接 模板题已不叫题.. 三维凸包+凸包重心+点到平面距离(体积/点积)  体积-->混合积(先点乘再叉乘) #include <iostream> #include<cstd ...

  6. hdu4449Building Design(三维凸包+平面旋转)

    链接 看了几小时也没看懂代码表示的何意..无奈下来问问考研舍友. 还是考研舍友比较靠谱,分分钟解决了我的疑问. 可能三维的东西在纸面上真的不好表示,网上没有形象的题解,只有简单"明了&quo ...

  7. hdu 4273 2012长春赛区网络赛 三维凸包中心到最近面距离 ***

    新模板 /* HDU 4273 Rescue 给一个三维凸包,求重心到表面的最短距离 模板题:三维凸包+多边形重心+点面距离 */ #include<stdio.h> #include&l ...

  8. HDU 4573 Throw the Stones(动态三维凸包)(2013 ACM-ICPC长沙赛区全国邀请赛)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4573 Problem Description Remember our childhood? A fe ...

  9. POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)

    POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...

随机推荐

  1. orcale数据恢复

    在操作数据时,不小心改错了表中的数据,想恢复到之前的数据,则可用以下方法: 1.首先我们需要通过dbms_flashback.get_system_change_number,它可以获取系统当前的SC ...

  2. jQuery ajax调接口时跨域

    解决方法提炼 一.jsonp方法 在前端ajax配置jsonp参数,在后台配置jsonp设置,具体方法自行百度 二. 参考同源策略 把前端静态页面放在tomcat内webapp下,和后台文件同目录, ...

  3. JDBC URL格式定制

    数据库URL制定: 当加载的驱动程序,可以建立程序中使用DriverManager.getConnection()方法的连接.为方便参考,让列出了三个重载DriverManager.getConnec ...

  4. 无需安装 vsftpd , 直接使用 FTP 来管理 docker 容器中的文件

    无图无真相,先放个效果图:     背景 使用 docker 来跑一些服务很方便,但是有的时候想管理容器里面的文件却很麻烦 -- 一般常规做法有3种: 通过数据卷或数据卷容器的方式 启动容器的时候时候 ...

  5. js 日期格式化及日期增减

    //Demo:new Date().format("yyyy-MM-dd hh:mm:ss.SSS") Date.prototype.format = function (form ...

  6. Asp ose.Tota l for .NET 2015

    How to license Aspose.Total for .NET products Add "License.cs" [C#] OR "License.vb&qu ...

  7. 用jquery实现的简单数据双向绑定

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. 使用websploit在局域网全自动渗透

    原理为 websploit调用dnsdpoof进行dns欺骗配合神器metasploit的web_autopwn模块进行渗透:特点:过程基本全自动. 终端输入websploit打开websploit: ...

  9. 阅读Configuration源码

    一.阅读类注释 ①.Configuration的实例允许应用程序使用指定的属性映射文件来创建一个SessionFactory. ②.通常在一个应用程序中创建一个单一的Configuration对象,· ...

  10. T-sql中的三种分页查询

    USE [APS_Future_FT] GO /****** Object: StoredProcedure [dbo].[A_PagingAndSorting] Script Date: 2013/ ...