POJ3348Cows【凸包+多边形求面积】
来源:互联网 发布:手机租号软件 编辑:程序博客网 时间:2024/05/04 13:05
Description
Your friend to the south is interested in building fences and turning plowshares into swords. In order to help with his overseas adventure, they are forced to save money on buying fence posts by using trees as fence posts wherever possible. Given the locations of some trees, you are to help farmers try to create the largest pasture that is possible. Not all the trees will need to be used.
However, because you will oversee the construction of the pasture yourself, all the farmers want to know is how many cows they can put in the pasture. It is well known that a cow needs at least 50 square metres of pasture to survive.
Input
The first line of input contains a single integer, n (1 ≤ n ≤ 10000), containing the number of trees that grow on the available land. The next n lines contain the integer coordinates of each tree given as two integers x and yseparated by one space (where -1000 ≤ x, y ≤ 1000). The integer coordinates correlate exactly to distance in metres (e.g., the distance between coordinate (10; 11) and (11; 11) is one metre).
Output
You are to output a single integer value, the number of cows that can survive on the largest field you can construct using the available trees.
Sample Input
40 00 10175 075 101
Sample Output
151
题意:给出一些点圈出一个最大面积每50平方养一头牛问最多能养多少牛
#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>using namespace std;struct point{int x,y;}A[10010],result[10010];int dist(point a,point b){return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}int cp(point p1,point p2,point p3){return (p3.x-p1.x)*(p2.y-p1.y)-(p3.y-p1.y)*(p2.x-p1.x);}bool cmp(point a,point b){int ans=cp(A[0],a,b);if(ans==0)return dist(A[0],a)-dist(A[0],b)<=0;else return ans>0;}int main(){int n,i,j;while(scanf("%d",&n)!=EOF){int pos=0;for(i=0;i<n;++i){scanf("%d%d",&A[i].x,&A[i].y);if(A[pos].y>=A[i].y){if(A[pos].y==A[i].y){if(A[pos].x>A[i].x)pos=i;}else pos=i;}}if(n<3){printf("0\n");continue;}point temp;int top=1;temp=A[0];A[0]=A[pos];A[pos]=temp;sort(A+1,A+n,cmp);result[0]=A[0];result[1]=A[1];for(i=2;i<n;++i){while(cp(result[top-1],result[top],A[i])<0)top--;result[++top]=A[i];}double s=0;for(i=0;i<=top;++i){double area=(result[(i+1)%(top+1)].x*result[i].y-result[(i+1)%(top+1)].y*result[i].x)/2.0;s+=area;}printf("%d\n",(int)(s/50.0));}return 0;}
- POJ3348Cows【凸包+多边形求面积】
- poj3348Cows(凸包求多边形面积)
- POJ 3348 Cows 凸包+求多边形面积
- 凸包 及 多边形面积
- BSOJ1478:多边形面积 凸包
- 【Algorithm】 多边形+凸包+面积
- 求不规则多边形面积
- 多边形求面积,
- hdu2036 求多边形面积
- hdu2036 求多边形面积
- Hdu2036-求多边形面积
- 怎样求多边形面积
- 求多边形面积
- hud2036 求多边形面积
- 求多边形面积
- 求多边形面积
- HDU2036 求多边形面积
- 求多边形的面积
- Android项目中module的“must not contain source root....”问题
- 完全二叉树求叶子节点个数
- UIScrollView
- 求20W内全部素数
- Matlab中的点运算
- POJ3348Cows【凸包+多边形求面积】
- testlink使用_李晓亭
- NSTimer
- WordPress基础入门
- web应用请求限流控制
- HDU1049 - Climbing Worm (模拟)
- nginx应用
- 程序员面试题集锦
- 扫描系统图片文件和视频文件