凸边形外壳
来源:互联网 发布:阿里云国际版价格 2017 编辑:程序博客网 时间:2024/06/10 18:45
凸边形外壳
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
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 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
Sample Input
240 01 00 11 120 00 1
Sample Output
1.00.0
Author
题意是说给定一些点求包含这些点的最小凸边形面积,直接套用模板做的。。。
#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;
}
- 凸边形外壳
- 凸边形外壳
- 凸边形外壳
- 凸边形外壳(求凸包面积)
- 关于是否凸边形的判断
- FZU 2148 Moon Game 判断凸边形
- 杭电2108判断凹凸边形
- 凸边形最优三角剖分
- OpenGL绘制填充非凸边形
- 凸边形最优三角剖分问题
- 由点集序列或数组创建凸边形
- FZU 2148 Moon Game(判断凸边形(凹边形))
- 判断点在任意多边形(包括凹凸边形)内
- OpenCV函数cvConvexHull2由点集序列或数组创建凸边形
- 判断点在任意多边形(包括凹凸边形)内
- 判断点在任意多边形(包括凹凸边形)内
- 凸边界搜索
- 凸边行判断
- KafkaConsumer及其监控
- 【Java】迭代的几种控制方法
- C++ primer(第五版) 练习 5.9 个人code
- 编译内核模块出现 include/linux/autoconf.h or include/config/auto.conf are missing.解决方法
- perl dbm文件操作总结
- 凸边形外壳
- HWOJ 字符统计
- 第三方
- ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务
- Tk Tutorial - 12. Canvas
- 使用CCtrlTab控件嵌入的子对话框按钮等控件不能用
- 如何避免在Block里用self造成循环引用
- KVM克隆虚拟机
- 大话重构连载7:重构是一系列的等量变换