poj 3528 & poj 2974 Ultimate Weapon(3D凸包求表面积)

Ultimate Weapon
Time Limit: 2000MS Memory Limit: 131072K
Total Submissions: 1499 Accepted: 742

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

题目:http://poj.org/problem?id=3528

Poj 2974与这道题类似

题意:给你空间n个点,让你求一个包含所有点的凸多面体,使得面积最小。。。

分析:面积最小的多面体,肯定就是n个点构成的凸包,贴个凸包模板就行。。。

PS:下面这个模板从NOI选手的资料中拿到的,特别短,用的是卷包裹法,不过貌似必须保证四点不共面,要不就会出错,具体去试试hdu 3662就知道了

所以,我还是打算自己实现个随机增量的写法。。。

代码:

#include <cmath>
#include <cstdio>
#include <set>
#include <map>
#include <vector>
#define NMax 1000
using namespace std;
struct point{
	double x,y,z;
	point(){}
	point(double _x,double _y,double _z):x(_x),y(_y),z(_z){}
};
point operator-(const point &a, const point &b){
	return point(a.x-b.x,a.y-b.y,a.z-b.z);
}
double operator*(const point &a,const point &b){
	return a.x*b.x+a.y*b.y+a.z*b.z;
}
point operator^(const point &a,const point &b){
	return point(a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x);
}
double Volcume(const point &a,const point &b,const point &c,const point &d){
	return ((b-a)^(c-a))*(d-a);
}
set<pair<int,int> > Set;
vector<pair<int,pair<int,int> > > Faces;
point P[NMax];
int N;
void wrap(int a,int b){
	if (Set.find(make_pair(a,b))==Set.end()){
		int c=-1;
		for (int i=0;i<N;i++)if (i!=a && i!=b){
			if (c==-1 || Volcume(P[c],P[a],P[b],P[i])>0)
				c=i;
		}
		if (c!=-1){
			Faces.push_back(make_pair(a,make_pair(b,c)));
			Set.insert(make_pair(a,b));
			Set.insert(make_pair(b,c));
			Set.insert(make_pair(c,a));
			wrap(c,b);wrap(a,c);
		}
	}
}
double Sqr(double x)
{
    return x*x;
}
double Dis(point p,point q)
{
    return sqrt(Sqr(p.x-q.x)+Sqr(p.y-q.y)+Sqr(p.z-q.z));
}
double area(point p,point q,point r)
{
    double a=Dis(p,q),b=Dis(p,r),c=Dis(q,r),t=(a+b+c)/2;
    return sqrt(t*(t-a)*(t-b)*(t-c));
}
double ans;
int main()
{
	scanf("%d",&N);
	for (int i=0;i<N;i++)scanf("%lf%lf%lf",&P[i].x,&P[i].y,&P[i].z);
	for (int i=1;i<N;i++)if (P[i].x<P[0].x)swap(P[0],P[i]);
	for (int i=2;i<N;i++)if (
		(P[i].x-P[0].x)*(P[1].y-P[0].y)>
		(P[i].y-P[0].y)*(P[1].x-P[0].x))swap(P[1],P[i]);
	wrap(0,1);
	ans=0;
	for(int i=0;i<(int)Faces.size();i++)
        ans+=area(P[Faces[i].first],P[Faces[i].second.first],P[Faces[i].second.second]);
    printf("%.3lf\n",ans);
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值