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. HTTP协议(持续更新)

    http请求由三部分组成,分别是:请求行.消息报头.请求正文 HTTP(超文本传输协议)是一个基于请求与响应模式的.无状态的.应用层的协议,常基于TCP的连接方式,HTTP1.1版本中给出一种持续连接 ...

  2. python SQLAchemy外键关联

    join 1.利用filter import sqlalchemy from sqlalchemy import create_engine from sqlalchemy.ext.declarati ...

  3. redis 存取问题

    今天在写短信接口时候,要把验证码存到缓存里面.因为之前别人已经写的有案例,按照之前写的,获取 值.存到数据库,存到redis. 因为有过期时间,需要传过期时间.但是怎么都是不出来... 源码: @Ov ...

  4. Windows下 Mysql启动报1067解决方法

    前几天刚入职安装了一下Mysql  刚开始能打开  今天去公司发现启动不了服务 报1067错误, 在网上查看了一些方法,好多种版本..以下是本人的解决方法 1.打开运行-事件查看器--Windows日 ...

  5. Hadoop HA集群的搭建

    HA 集群搭建的难度主要在于配置文件的编写, 心细,心细,心细! ha模式下,secondary namenode节点不存在... 集群部署节点角色的规划(7节点)------------------ ...

  6. Linux ->> Ubuntu 14.04 LTE下安装JDK 1.8

    先到Oracle官网的下载中心下载JDK8的tar包到本地. 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-dow ...

  7. Infragist ics Ult imate 2015 Vol.1 - Product Keys

    Ultimate ProductKeys 2015 Vol.1: 9122-1900164-4504144 9122-9300855-3994197 9122-7600717-4579130 9122 ...

  8. 【Leetcode】【Easy】Same Tree

    Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...

  9. Retrofit-入门使用

    1. 在模块目录下的build.gradle dependencies { compile "com.squareup.retrofit2:retrofit:2.1.0" comp ...

  10. RBTree和AVL

      红黑树和AVL的相同:都是平衡二叉树,所以插入删除修改查询都非常高效. 红黑树和AVL的区别: 红黑树:  不是要求绝对平衡,付出的代价是要着色,查询次数可能会多一层,好处是减少旋转次数. AVL ...