poj 3348 Cows (凸包面积)
来源:互联网 发布:网络安全书 编辑:程序博客网 时间:2024/06/15 03: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 y separated 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
Source
[Submit] [Go Back] [Status] [Discuss]
题目大意:给出一些树,可以选择任意的树圈地,每头牛需要50 square metres ,求最多放多少头牛。
题解:求凸包面积
叉积求面积
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>#define N 10003#define LL long longusing namespace std;struct vector {LL x,y;vector (LL X=0,LL Y=0){x=X,y=Y;}}p[N],ch[N];typedef vector point;vector operator -(vector a,vector b){return vector (a.x-b.x,a.y-b.y);}bool operator <(vector a,vector b){return a.x<b.x||a.x==b.x&&a.y<b.y;}int n,m;LL cross(vector a,vector b){return a.x*b.y-a.y*b.x;}void convexhull(point *p,int n,point *ch){sort(p+1,p+n+1);if (n==1) {ch[m++]=p[1];return ;}m=1;for (int i=1;i<=n;i++){while (m>2&&cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<0) m--;ch[m++]=p[i]; }int k=m;for (int i=n-1;i>=1;i--){while (m>k&&cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<0) m--;ch[m++]=p[i];}m--;}LL Abs(LL x){if (x<0) return -x;else return x;}int main(){freopen("a.in","r",stdin);while (scanf("%d",&n)!=EOF){for (int i=1;i<=n;i++) scanf("%lld%lld",&p[i].x,&p[i].y);if (n<3) {printf("0\n");continue;}convexhull(p,n,ch);LL area=0; m--;//for (int i=1;i<=m;i++) cout<<ch[i].x<<" "<<ch[i].y<<endl;for (int i=2;i<=m-1;i++) area+=Abs(cross(ch[i]-ch[1],ch[i+1]-ch[1]));printf("%lld\n",(LL)area/100); }}
- 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 Cows (凸包面积)
- POJ 3348 Cows (计算凸包面积)
- poj 3348 Cows(凸包+叉积求面积)
- POJ 3348 Cows (凸包+求面积)
- POJ 3348 Cows (凸包+多边形面积)
- POJ 3348 Cows 寻找凸包 凸包面积
- POJ 3348 Cows 凸包+求多边形面积
- POJ 3348 Cows 凸包 + 多边形面积公式
- 某高校关于2011年学生注册注意事项的通知
- YV12,I420,YUV420P的区别
- Linux系统函数write()函数
- printf的格式控制
- Spring中的设计模式--工厂方法模式
- poj 3348 Cows (凸包面积)
- makefile简介与入门
- 数据库灾难...
- Java's HelloWorld
- 文章标题
- ERROR: HHH000388: Unsuccessful: create table
- Android 滑动返回上一级页面
- 无缝动画原理
- matlab 形态学函数的应用