Poj 3528 & poj 2974 ultimate weapon (3D Convex Hull for surface area)

Source: Internet
Author: User
Ultimate weapon
Time limit:2000 ms   Memory limit:131072 K
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 each Val. 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 numberN-- The number of battleships. (1 ≤N≤ 500)
FollowingNLines each contains three integers presenting the position of one battleship.

Output

The minimal area rounded to three decimal places.

Sample Input

40 0 04 0 02 3 01 1 2

Sample output

19.137

Hint

There are no four coplaner battleships.

Source

Poj founder monthly contest-2008.03.16, Jiang Liyang

Question: http://poj.org/problem? Id = 3528

Poj 2974 is similar to this question

Question: give you a space of N points. Ask for a convex polygon containing all points to minimize the area...

Analysis: the polygon with the smallest area must be a convex bag consisting of n points. Just paste a convex bag template...

PS: The following template was obtained from Noi players' materials. It is very short and uses the volume package method. However, it seems that four points are not in total, or an error may occur, please try HDU 3662.

Therefore, I plan to write a random increment on my own...

Code:

#include <cmath>#include <cstdio>#include <set>#include <map>#include <vector>#define NMax 1000using 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;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.