POJ2007 凸包计算
来源:互联网 发布:乐乎pt上不去 编辑:程序博客网 时间:2024/06/06 20:05
Scrambled Polygon
和POJ1696蚂蚁那道题几乎一个意思……看看图就懂了。不多说思路了,直接排序就好,O(N^2);
CODE:
#include <iostream>#include <cstring>#include <algorithm>#include <cstdio>#include <cmath>#define cross(p1,p2,p3) ((p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y))#define crossOp(p1,p2,p3) sign(cross(p1,p2,p3))using namespace std;const double EPS = 1e-8;inline int sign(double a){ return a < -EPS ? -1 : a > EPS;}struct Point{ double x, y; Point() { } Point(double _x, double _y) : x(_x), y(_y) { } Point operator+(const Point&p) const { return Point(x + p.x, y + p.y); } Point operator-(const Point&p) const { return Point(x - p.x, y - p.y); } Point operator*(double d) const { return Point(x * d, y * d); } Point operator/(double d) const { return Point(x / d, y / d); } bool operator<(const Point&p) const { int c = sign(x - p.x); if (c) return c == -1; return sign(y - p.y) == -1; } double dot(const Point&p) const { return x * p.x + y * p.y; } double det(const Point&p) const { return x * p.y - y * p.x; } double alpha() const { return atan2(y, x); } double distTo(const Point&p) const { double dx = x - p.x, dy = y - p.y; return hypot(dx, dy); } double alphaTo(const Point&p) const { double dx = x - p.x, dy = y - p.y; return atan2(dy, dx); } void read() { scanf("%lf%lf", &x, &y); } double abs() { return hypot(x, y); } double abs2() { return x * x + y * y; } void write() { cout << "(" << x << "," << y << ")" << endl; }};Point temp;bool cmp(Point a,Point b){ return a.y<b.y;}bool cmp_angel(Point a,Point b){ int t=crossOp(temp,a,b); if(t<0) { //说明a的再b的顺时针方向上,说明极角小 return false ; } else if(t>0) { return true; } else { int da=temp.distTo(a); int db=temp.distTo(b); if(da<=db) { return false ; } else { return true; } }}Point p[52];int main(){ int n,m,i=0; while(cin>>n>>m) { p[i].x=n; p[i].y=m; i++; } int l=i; temp=p[0]; temp.write(); for(int j=1; j<l; j++) { sort(p+j,p+l,cmp_angel); temp=p[j]; temp.write(); }}
- POJ2007 凸包计算
- POJ2007 凸包
- poj2007凸包graham逆时针输出
- Scrambled Polygon(poj2007极角排序输出凸包)
- POJ2007
- poj2007
- poj2007
- poj2007
- poj2007
- [POJ2007]Scrambled Polygon(计算几何)
- ACM-计算几何之Scrambled Polygon——poj2007
- UVA10652【凸包计算】
- 计算凸包算法
- 计算几何-凸包
- 计算几何中的凸包计算
- [计算几何]凸包算法
- 计算几何之凸包
- POJ1113 凸包周长计算
- zoj Heavy Cargo
- mysql优化实例
- 实体关系的定义
- "make: *** [out/target/common/obj/PACKAGING/checkapi-current-timestamp] 错误 38" 问题解决
- Hive表分区
- POJ2007 凸包计算
- iBatis 到 MyBatis区别
- 实体关系的使用
- S-Record格式详解
- 对于VS里面的几个插件的最初认识
- VS2010 关于CDockablePane 关闭事件
- Memcached高速缓存服务器部署及应用(一、Memcached在Windows平台下安装与配置)
- 天气预报的Ajax效果
- 7 (phonegap源码分析) 平台相关模块和初始化(platform)