POJ 3348 Cows 凸包面积
题目大意:连接个点,求围成的面积并除以50(向下取整)
题目思路:就是求凸包面积:按逆时针方向为凸包上每条边指定方向,对于每条边AB,累加(AXB)/2的值。
#include<cstdio> #include<cstdlib> #include<cmath> #include<iostream> #include<algorithm> #include<cstring> #include<vector> #include<queue> #define INF 0x3f3f3f3f #define MAX 100005using namespace std;struct node {int x,y,id; }point[MAX];int n,ans[MAX],Stuck[MAX],top;bool cmp(struct node A,struct node B) {if(A.x < B.x)return true;else if(A.x==B.x && A.y < A.y)return true;return false; }int Cross(int x1,int y1,int x2,int y2,int x3,int y3) {return (x1-x2)*(y1-y3)-(x1-x3)*(y1-y2); }double Area() {double sum=0.0;for(int i=1;i<=top;i++)sum+=(point[Stuck[i-1]].x*point[Stuck[i]].y-point[Stuck[i]].x*point[Stuck[i-1]].y);return fabs(sum/2); }void Graham() {int len;top=1;for(int i=0;i<2;i++)Stuck[i]=i;for(int i=2;i<n;i++){while(top>0 && Cross(point[Stuck[top]].x,point[Stuck[top]].y,point[Stuck[top-1]].x,point[Stuck[top-1]].y,point[i].x,point[i].y)<=0)top--;Stuck[++top]=i;}len=top;Stuck[++top]=n-2;for(int i=n-3;i>=0;i--){while(top!=len && Cross(point[Stuck[top]].x,point[Stuck[top]].y,point[Stuck[top-1]].x,point[Stuck[top-1]].y,point[i].x,point[i].y)<=0)top--;Stuck[++top]=i;} }int main() {while(scanf("%d",&n)!=EOF){memset(ans,0,sizeof(ans));for(int i=0;i<n;i++){scanf("%d%d",&point[i].x,&point[i].y);point[i].id=i;}if(n<3){printf("0\n");continue;}sort(point,point+n,cmp);Graham();double ans=Area();int sum=ans/50;printf("%d\n",sum);}return 0; }
View Code
转载于:https://www.cnblogs.com/alan-W/p/6021819.html
POJ 3348 Cows 凸包面积相关推荐
- POJ 3348 Cows(凸包面积)
有 n 棵树,给出他们的顶点,每头牛的活动范围为 50 平方米,以 n 棵树为顶点围成篱笆,问最多可以容纳多少头牛 求凸包面积模板题 const int N=1e4+5;int i,j,k;int n ...
- POJ 3348 Cows
题目大意: 给你n棵树,可以用这n棵树围一个圈,然后在圈里面可以养牛,每个牛需要50平方米的空间,问最多可以养多少牛? 其实就是求一个凸包,计算凸包面积,然后除以50,然后就得到答案,直接上模板了. ...
- poj 3348 Cows 求凸包以及凸包的面积
题目来源: http://poj.org/problem?id=3348 1:任意多边形p[0,n-1]的面积为 for(int i=0 ; i<=n-1 ; i++){ sum+= (sk[i ...
- POJ 3348 Cows(二维凸包)
题目链接:https://cn.vjudge.net/problem/POJ-3348 题意:有一些数,坐标已知,要用这些树作为篱笆的顶点圈一块多边形的地养牛,每头牛占地大小50,问最多能养多少头牛. ...
- POJ 1654 Area 凸包面积
水题直接码... /********************* Template ************************/ #include <set> #include < ...
- POJ 2481 Cows POJ 2352 Stars(树状数组妙用)
题目链接:POJ 2481 Cows POJ 2352 Stars 发现这两个题目都跟求逆序数有着异曲同工之妙,通过向树状数组中插入点的位置,赋值为1,或者++,然后通过求和来判断比当前 点 &quo ...
- poj 1654 Area 多边形面积
/* poj 1654 Area 多边形面积题目意思很简单,但是1000000的point开不了 */ #include<stdio.h> #include<math.h> # ...
- POJ 2481 Cows
传送门:POJ 2481 Cows Time Limit: 3000MS Memory Limit: 65536K Problem Description Farmer John's cows hav ...
- 用python批量获取cad中线段点组成的凸包 + 面积
用python批量获取cad中线段点组成的凸包 + 面积 效率实在太低,还是用c# 吧 import win32com.client import pythoncom import tubao imp ...
最新文章
- 谷歌AI乳腺癌检测超过人类,LeCun质疑引起讨论
- python 数据增强
- 安洵杯——game(混淆控制流平坦化)
- redis五种数据类型的应用场景_Redis五种不同的数据类型
- 柱状图python_python柱状图一行
- 用Google App Engine做个人代理服务器
- 【转】Win2008 r2 远程桌面授权已过期的解决办法
- IDC:安全性、价格和低复杂性是企业采用SD-WAN的主要动因
- 最长公共子序列(LCS) 最长公共子串
- Oracle sql语句 待新增(新增字段)
- 可逆矩阵性质总结_逆矩阵的定义与性质.doc
- 无线WiFi漫游的基本原理及搭建
- vue在图片标注矩形框
- 拼拼有礼开发功能总结 拼拼有礼APP开发分享
- defineEmit
- 上班第一天(4)--一个程序员的成长史(13)
- 统计分组的原则是要体现什么_统计分组原则是什么?统计分组的形式是什么
- php上传txt文件读取乱码
- [小迪安全20-23天]upload-laps
- Google Earth Engine(GEE)——Sentinel2 TOA反射率数据去云