POJ 3348 (凸包)
来源:互联网 发布:后藤藤四郎极化数据 编辑:程序博客网 时间:2024/06/08 05:49
题意是求凸包的面积。
没什么坑, 板子题
#include <cstring>#include <cmath>#include <iostream>#include <algorithm>#include <cstdio>using namespace std;typedef unsigned long long ll;#define maxn 51111#define pi acos (-1)#define rotate Rotateconst double eps = 1e-8;int dcmp (double x) { if (fabs (x) < eps) return 0; else return x < 0 ? -1 : 1;}struct point { double x, y; point (double _x = 0, double _y = 0) : x(_x), y(_y) {} point operator - (point a) const { return point (x-a.x, y-a.y); } point operator + (point a) const { return point (x+a.x, y+a.y); } bool operator < (const point &a) const { return x < a.x || (x == a.x && y < a.y); } bool operator == (const point &a) const { return dcmp (x-a.x) == 0 && dcmp (y-a.y) == 0; }};point operator * (point a, double p) { return point (a.x*p, a.y*p);}double cross (point a, point b) { return a.x*b.y-a.y*b.x;}double dot (point a, point b) { return a.x*b.x + a.y*b.y;}int n, m, tot;point p[maxn], ch[maxn];int ConvexHull () { sort (p, p+n); int m = 0; for (int i = 0; i < n; i++) { while (m > 1 && cross (ch[m-1]-ch[m-2], p[i]-ch[m-1]) <= 0) m--; ch[m++] = p[i]; } int k = m; for (int i = n-2; i >= 0; i--) { while (m > k && cross (ch[m-1]-ch[m-2], p[i]-ch[m-1]) <= 0) m--; ch[m++] = p[i]; } if (n > 1) m--; return m;}double dis (point a, point b) { double xx = a.x-b.x, yy = a.y-b.y; return sqrt (xx*xx + yy*yy);}double PolygonArea (point *p, int n) { double ans = 0; for (int i = 1; i < n-1; i++) { ans += cross (p[i]-p[0], p[i+1]-p[0]); } return ans/2;}int main () { //freopen ("in", "r", stdin); ios::sync_with_stdio(0); while (cin >> n) { for (int i = 0; i < n; i++) { cin >> p[i].x >> p[i].y; } m = ConvexHull (); printf ("%lld\n", (long long)(floor)(PolygonArea (ch, m)/50.0)); } 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 Cows (凸包面积)
- POJ 3348 Cows (凸包面积)
- poj 3348 Cows 凸包模板题
- POJ 3348 Cows(凸包+多边形面积)
- [POJ 3348] Cows 凸包模板
- POJ 3348 Cows(凸包面积)
- POJ 3348 Cows(凸包面积)
- POJ 3348:Cows 凸包+多边形面积
- POJ 3348 (凸包面积)
- POJ 3348 Cows (凸包面积)
- jQuery实现购物车物品数量的加减
- 字符与ASCII码十六制之间的关系
- iOS 消除对应的警告!
- TCP传输小数据包效率问题
- Android下载APK并自动安装
- POJ 3348 (凸包)
- 学习 SpiderMonkey
- 【DuiLib入门基础】九宫格corner属性详细解释
- JDBC连接数据库(oracle)操作
- 获取requestBody中的内容
- recyclerview 滚动状态
- linux信号汇总大全
- c# 如何使用DllImport
- matlab学习笔记(三)---图像的代数运算