poj3348 Cows【凸包面积】
来源:互联网 发布:淘宝热卖商品排行榜 编辑:程序博客网 时间:2024/06/04 01:10
题目链接:http://poj.org/problem?id=3348
题意:给你n个点,让你围城一个多边形,也就是求凸包,然后50平方米才能有一头牛,问你这些点构成的多边形能养几头牛
解析:求凸包面积/50,向下取整
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <string>using namespace std;const int maxn = 1e5+100;const double eps = 1e-10;const double pi = acos(-1.0);struct point{ double x,y; point() {} point(double _x,double _y) { x = _x; y = _y; } bool operator < (const point &b) const { if(y==b.y) return x<b.x; return y<b.y; }}a[maxn],ans[maxn];double x_mul(point p0,point p1,point p2){ return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);}double dis(point p1,point p2){ return sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));}bool cmp(point t1,point t2){ double tmp = x_mul(a[0],t1,t2); if(tmp==0) return dis(a[0],t1)<dis(a[0],t2); else return tmp>0;}double graham(int n){ sort(a,a+n); sort(a+1,a+n,cmp); ans[0] = a[0]; ans[1] = a[1]; ans[2] = a[2]; int top = 2; for(int i=3;i<n;i++) { while(top>=2&&x_mul(ans[top-1],ans[top],a[i])<0) top--; ans[++top] = a[i]; } double res = 0; for(int i=0;i<top;i++) res += x_mul(point(0.0,0.0),ans[i],ans[i+1]); res += x_mul(point(0.0,0.0),ans[top],ans[0]); return res/2.0;}int main(void){ int n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%lf %lf",&a[i].x,&a[i].y); double sum = graham(n)/50.0; printf("%.0f\n",floor(sum)); return 0;}
0 0
- poj3348 Cows【凸包面积】
- poj3348 Cows 凸包+多边形面积 水题
- Cows(poj3348凸包的面积)
- POJ3348--cows--凸包
- [POJ3348]Cows(凸包)
- poj3348 Cows【凸包模板】
- POJ3348 凸包面积计算
- poj3348-Cows 求凸包及其面积
- Cows(凸包面积)
- POJ3348-Cows
- Poj3348 Cows
- 【poj3348】 Cows
- POJ3348-凸包
- 【BZOJ3348】Cows【凸包】【凸包面积】
- POJ 3348 Cows(凸包面积)
- Poj 3348 Cows (凸包面积)
- POJ 3348 Cows (凸包面积)
- POJ 3348 Cows (凸包面积)
- 信道安全
- 雪城大学信息安全讲义 3.1 Set-UID 机制如何工作
- 腾讯课堂IMWeb Vue.js 笔记
- Android中AsyncTask的介绍,示例和原理分析
- react-router 学习笔记
- poj3348 Cows【凸包面积】
- Android 网络请求 框架
- 1023. Have Fun with Numbers (20)
- UVA 7340 Sum of MSLCM
- centos7环境下搭建storm集群
- 浏览器兼容问题项目总结(五)table中td和li高度问题
- (原创)分享自己写的几个工具类(四)BigDecimal精确计算
- MTK lk源码解析7( lk 阶段aboot.c 解析)
- js中如何查看原型