凸边形外壳

凸边形外壳

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 27   Accepted Submission(s) : 4

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

Problem Description

Maxwell is a naughty boy.

One day, he fouled the white and clean wall with ink. Since his mother will come back home soon, Maxwell wanted to find a white convex polygon to cover these ink drops. Could you tell him the minimal area of the convex polygon which can cover all the ink drops?

Now, given the coordinates of these ink drops, you will answer the minimal area of the convex polygon that can cover all the ink drops.

Input

The first line of the input is a positive integer T. T is the number of the test cases followed.

The first line of each test case is a positive integer N (0<N<=10^5). N is the number of the ink drops. After that, N lines are followed. The ith line contains two integers Xi and Yi (0<=Xi, Yi<20000) which tell you the coordinate of the ith ink drops. There
may be one or more spaces between these integers.

Output

The output of the program should consist of one line of output for each test case. The output of each test case only contains the minimal area of the convex polygon. The area is a real number that has one digit after the decimal
point. No redundant spaces are needed.

Sample Input

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

Sample Output

1.0
0.0

Author

HYNU



题意是说给定一些点求包含这些点的最小凸边形面积,直接套用模板做的。。。

#include <iostream>

#include <cmath>

#include <algorithm>

#include <cstdio>

using namespace std;

#define MAX 100002

#define eps 1e-9

int n,cnt;

struct Point

{

double x,y;

Point (){}

Point ( double x, double y ) : x(x) , y(y) {}

}p[MAX],ch[MAX];

typedef Point Vector;

Point operator - ( Point a , Point b ) { return Point ( a.x - b.x , a.y - b.y ); }

bool cmp ( Point a , Point b )  //将每个点通过优先x最小然后y最小的顺序来排序

{

if ( a.x != b.x ) return a.x < b.x;

else return a.y < b.y;

}

int dcmp ( double x )

{

if ( fabs ( x ) < eps ) return 0;

else return x < 0 ? -1 : 1;

}

double Cross ( Vector u , Vector v )  //叉乘

{

return u.x * v.y - u.y * v.x;

}

int ConvexHull ( Point *p , Point *ch )  //求凸包Andrew算法

{

sort ( p , p + n , cmp );

int m = 0;

for ( int i = 0 ; i < n ; i ++ )

{

while ( m > 1 && dcmp ( Cross ( ch[m-1] - ch[m-2] , p[i] - ch[m-2] ) ) <= 0 ) m--;

ch[m++] = p[i];

}

int k = m;

for ( int i = n - 2 ; i >= 0 ; i -- )

{

while ( m > k && dcmp ( Cross ( ch[m-1] - ch[m-2] , p[i] - ch[m-2] ) ) <= 0 ) m --;

ch[m++] = p[i];

}

return m;

}

double PolygonArea ( Point *ch )  //求多边形面积(因为是凸包所以它的有向面积就是它本身的面积

{

double area = 0;

for ( int i = 1 ; i < cnt -1 ; i ++ )

{

area += Cross ( ch[i] - ch[0] , ch[i+1] - ch[0] );

//cout << area << endl;

}

return area / 2.0;

}

int main()

{

int t;

scanf("%d",&t);

while ( t-- ){

scanf ( "%d" , &n );

for( int i = 0 ; i < n ; i ++ )

scanf ( "%lf%lf" , &p[i].x , &p[i].y );

cnt = ConvexHull ( p , ch );

printf ( "%.1lf\n" , PolygonArea( ch ) );

}

return 0;

}

凸边形外壳

时间: 2024-10-11 21:31:24

凸边形外壳的相关文章

FZU 2148 Moon Game 判断凸边形

点击打开链接 Problem 2148 Moon Game Accept: 512    Submit: 1419 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description Fat brother and Maze are playing a kind of special (hentai) game in the clearly blue sky which we can just consider as a k

A Round Peg in a Ground Hole POJ - 1584(凸边形与圆相交)

A Round Peg in a Ground Hole POJ - 1584 题目链接:https://vjudge.net/problem/POJ-1584#author=0 题意:要求钉子要钉入孔内,判断能否在指定点钉入 思路:先判断这些点围成的多边形是不是凸多边形,如果是那么判断圆是否在凸边形里,若在那么就输出“PEG WILL FIT“,不在凸边形里就输出“PEG WILL NOT FIT”,如果都不是凸边形那么输出“HOLE IS ILL-FORMED” // // Created

重叠检测----凸边形

很多人都叫他  分离坐标轴方法 理论源自  凸集分离定理 wikipedia 上 Hyperplane separation theorem 他的内容是,如果能找到一条轴,使得两个物体在该轴上的投影互不重叠,那么这两个物体就是不相交的. 重点是如何找到这条轴. 以2D图形的每条边做为分离轴,使2个图形在分离轴的法线上投影,如上图,只要其中有一次 两图形投影不重叠,就可证明两图形不是重叠的. 关于两长方形的重叠检测: 依上理论 为每条边做分离轴,由于长方形为AABB,所以只要检测4条边. 由于最后

NYOJ 1103 —— m划分为n个正整数的个数

多边形划分 时间限制:1000 ms  |  内存限制:65535 KB 描述 Give you a convex(凸边形), diagonal n-3 disjoint divided into n-2 triangles(直线), for different number of methods, such as n=5, there are 5 kinds of partition method, as shown in Figure 输入 The first line of the inp

求多边形面积

杭电2036 开始想到用三边形法求面积 三角形海伦面积公式如下: 假设在平面内,有一个三角形,边长分别为a.b.c,三角形的面积S可由以下公式求得: S=sqrt(p(p-a)(p-b)(p-c)) 公式中的p为半周长: p=(a+b+c)/2 #include <stdio.h>#include <math.h>double c(double i,double j,double x,double y,double m,double n){ double s,p,a,b,c; a=

webgl圈中物体

这篇的标题非常不符合我的气质! 但是 如果带上那种 “不可能 姐姐 妹妹 君 套套 不要”等关键字标题的话 其他小伙伴就很难通过搜索引擎到这个地方来了! 所以还是使用这种简短大众的标题得了.. 注意标题中有个“圏” 字 我们讨论的并不是“选” 下面的圈中物体解决方案 其实已经把如何选中一个物体的问题一并搞定了 圈中物体 首先要有一条封闭曲线吧 那条曲线是由n个线段拼接起来的 我们要找到相交的那两条线段和那两条线段之间的所有线段 如图 相交的线段就是这两了 封闭曲线的起始和结束线段就是它们 不过还

线段树题目总结

一.单点更新 1.hdu1166 敌兵布阵:有N个兵营,每个兵营都给出了人数ai(下标从1开始),有四种命令,(1)"Addij",表示第i个营地增加j人.(2)"Sub i j",表示第i个营地减少j人.(3)"Query ij",查询第i个营地到第j个营地的总人数.(4)"End",表示命令结束.解题报告Here. 2.hdu1754 I Hate It:给你N个数,M个操作,操作分两类.(1)"QAB"

组合数学及其应用——卡特兰数

卡特兰数是组合数学中常见也是重要的特殊计数公式. 首先给出一个现实问题的模型: 给出凸多边形的边数n,求解该凸多边形内部不相交的对角线把这个区域分成三角形区域的方法数. 首先我们进行初步的分析,当n=2,h2=1,也就是说对于三角形,划分的情况数是1.这似乎有些不好理解,由于三角形内部无法添加对角线,所以符合情况的就是三角形本身,情况数为1. 下面我们讨论n取任意值的情况. 看下面的图. 考虑将n+1凸边形的子问题,即我们将AB视为基边,枚举C的位置,有n-1个可枚举位置,然后结合基本的计数原理

nyoj-1103-区域赛系列一多边形划分

http://acm.nyist.net/JudgeOnline/problem.php?pid=1103 区域赛系列一多边形划分 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 Give you a convex(凸边形), diagonal n-3 disjoint divided into n-2 triangles(直线), for different number of methods, such as n=5, there are 5 kinds of