POJ3348--cows--凸包
来源:互联网 发布:做java程序员能做多久 编辑:程序博客网 时间:2024/05/29 00:34
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
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>using namespace std;struct Point{int x,y;}point[10008],res[10008];bool cmp(Point a,Point b){if(a.x>b.x)return 0;else if(a.x==b.x)return a.y>b.y?0:1;else return 1;}bool ral(Point p1,Point p2,Point p3){return ((p3.y-p1.y)*(p2.x-p1.x)>(p2.y-p1.y)*(p3.x-p1.x));}double mianji(Point p1,Point p2,Point p3){return fabs(((p2.x-p1.x)*(p3.y-p1.y)-(p2.y-p1.y)*(p3.x-p1.x))/2.0);}int main(){int n;while(scanf("%d",&n)!=EOF){for(int i=0;i<n;i++){scanf("%d%d",&point[i].x,&point[i].y);}sort(point,point+n,cmp);int m=-1;for(int i=0;i<n;i++){while(m>=1&&(!ral(res[m-1],res[m],point[i]))){m--;}res[++m]=point[i];}int k=m;for(int i=n-2;i>=0;i--){while(m>k&&(!ral(res[m-1],res[m],point[i]))){m--;}res[++m]=point[i];}double S=0;for(int i=1;i<m;i++){S+=mianji(res[0],res[i],res[i+1]);}int sum=S/50;cout<<sum<<endl;}return 0;}
- POJ3348--cows--凸包
- [POJ3348]Cows(凸包)
- poj3348 Cows【凸包面积】
- poj3348 Cows【凸包模板】
- poj3348 Cows 凸包+多边形面积 水题
- Cows(poj3348凸包的面积)
- POJ3348-Cows
- Poj3348 Cows
- 【poj3348】 Cows
- POJ3348-凸包
- POJ3348 凸包面积计算
- POJ3348——Cows
- poj3348-Cows 求凸包及其面积
- poj3348 Cows (Graham Scan算法学习)
- poj3348
- poj3348
- poj3348
- poj3348
- CityEngine中的参数和属性以及通过属性筛选Object
- 被我的Fedora 17弄的很无奈···
- 自己写的C/C++编译器Doctors[软件+文档]
- 求输入的一个整数的各位数字之和
- jsp嵌入flex后,操作flex功能时禁用鼠标在页面的点击
- POJ3348--cows--凸包
- Hadoop MapReduce进阶 使用分布式缓存进行replicated join
- SSH支持Annotation集成 (Struts2 Spring3 Hibernate3)
- android 背光设置
- Splay解决区间问题[区间更新,区间求和]
- 简单计算机c++代码
- mongodb中分页显示数据集的学习
- Java类与对象的初始化
- 键入一个自然数 ,求这个自然数的所有约数之和