POJ 3348 求凸包面积
来源:互联网 发布:java计算n的阶乘 编辑:程序博客网 时间:2024/06/08 17:34
题意 : 就是让你求出凸包面积然后除以50
题解 :
- 凸包的求法
- 面积的求法
说一下面积的求法 : 和凸包的排序方式一样然后逆时针扫一遍凸包把所有的面积全部加起来就可以得到答案了。 (一定要先固定一个极点然后按照极角排序就可以了)
ps : 计算几何输入一定要用scanf;
#include <iostream>#include <algorithm>#include <cstring>#include <cmath>#include <cstdio>using namespace std;const double eps = 1e-8;const int maxn = 1e4 + 10;const double INF = 1e15 + 7;struct point { double x,y;}p[maxn],tu[maxn];point init;int n;double dist (point a,point b) { return sqrt ((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));}double cross (double x1,double y1,double x2,double y2) { return x1 * y2 - x2 * y1;}bool cmp (point a,point b) { if (fabs(cross(a.x - init.x, a.y - init.y, b.x - init.x, b.y - init.y)) < eps) { return dist(a, init) < dist(b, init); } else return cross(a.x - init.x, a.y - init.y, b.x - init.x, b.y - init.y) > 0;}int main () { ios_base :: sync_with_stdio(false); while (scanf ("%d",&n) != EOF) { double mix = 0,miy = INF; int pos = 1; for (int i = 1;i <= n; ++ i) { scanf ("%lf%lf",&p[i].x,&p[i].y); if (miy > p[i].y) { miy = p[i].y; pos = i; mix = p[i].x; } else if (fabs (miy - p[i].y) < eps) { if (mix > p[i].x) { mix = p[i].x; pos = i; } } } swap (p[1],p[pos]); init = p[1]; sort (p + 2,p + n + 1,cmp); tu[1] = p[1],tu[2] = p[2],tu[3] = p[3]; int tot = 3; for (int i = 4;i <= n; ++ i) { while (tot >= 3) { point p1,p2,p3; p1 = tu[tot]; p2 = tu[tot - 1]; p3 = p[i]; if (cross(p1.x - p2.x,p1.y - p2.y , p3.x-p1.x, p3.y - p1.y) < 0) tot --; else break; } tu[++tot] = p[i]; } init = tu[1]; sort (tu + 2,tu + tot + 1,cmp); double res = 0; for (int i = 2;i < tot; ++ i) { if (i != tot) { res += cross(tu[i].x - p[1].x, tu[i].y - p[1].y, tu[i + 1].x - p[1].x, tu[i + 1].y - p[1].y); } } int ans = floor(fabs (res) / 100); printf ("%d\n",ans); } return 0;}
阅读全文
0 0
- POJ 3348 求凸包面积
- POJ 3348 求凸包面积
- poj 3348 Cows(求凸包面积)
- POJ 3348 Cows 求凸包面积
- POJ 3348 || Cows(求凸包面积
- poj 3348(求凸包面积)
- poj 3348 Cows(求凸包面积)
- POJ 3348 Cows(求凸包面积)
- poj 3348 包凸求面积
- POJ 3348 Cows(凸包求面积)
- poj 3348 Cows 求凸包以及凸包的面积
- POJ 3348 Cows(凸包面积)
- Poj 3348 Cows (凸包面积)
- POJ 3348 Cows (凸包面积)
- POJ 3348 Cows (凸包面积)
- POJ 3348 Cows(凸包+多边形面积)
- POJ 3348 Cows(凸包面积)
- POJ 3348 Cows(凸包面积)
- 第二周项目3-体验复杂度(2)
- TypeError: slice indices must be integers or None or have an __index__ method
- 第二周 项目三 (2)汉诺塔
- 手风琴效果
- 回顾与展望
- POJ 3348 求凸包面积
- 备考pat
- angular.js 购物车
- C++ 标准库 bitset类型
- Sublime Text 3改变插件包安装位置
- dubbo入门
- SQL SERVER 2008用Select操作处理数据(四)——Where条件
- 2018科大讯飞校招---足球队
- pat1008