Cows(凸包面积)
来源:互联网 发布:唱给自己的歌网络战队 编辑:程序博客网 时间:2024/06/05 07:37
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 nextn lines contain the integer coordinates of each tree given as two integersx 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<map>#include<cmath>#include<vector>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;struct node{ int x; int y;}p[10005],P[10005];int multi(node A,node B,node C){ return (B.x-A.x)*(C.y-A.y)-(C.x-A.x)*(B.y-A.y);}double len(node A,node B){ return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));}bool cmp(node A,node B){ double pp=multi(p[0],A,B); if(pp>0) return true; if(pp<0) return false; return len(p[0],A)<len(p[0],B);}int main(){ int n; while(~scanf("%d",&n)){ for(int i=0;i<n;i++) { scanf("%d%d",&p[i].x,&p[i].y); if(p[i].y<p[0].y) swap(p[i],p[0]); if(p[i].y==p[0].y&&p[i].x<p[0].x) swap(p[i],p[0]); } if(n<3) { printf("0\n"); } else { sort(p+1,p+n,cmp); P[0]=p[0]; P[1]=p[1]; int tot=1; for(int i=2;i<n;i++) { while(tot>0&&multi(P[tot-1],P[tot],p[i])<=0) tot--; tot++; P[tot]=p[i]; } double sum=0; //求面积 for(int i=1;i<tot;i++) sum+=abs(multi(P[0],P[i],P[i+1])); printf("%d\n",(int)sum/100); } }}
- Cows(凸包面积)
- POJ 3348 Cows(凸包面积)
- poj 3348 Cows (凸包面积)
- POJ 3348 Cows (凸包面积)
- poj3348 Cows【凸包面积】
- 【BZOJ3348】Cows【凸包】【凸包面积】
- POJ 3348 Cows (计算凸包面积)
- poj 3348 Cows(凸包+叉积求面积)
- POJ 3348 Cows (凸包+求面积)
- POJ 3348 Cows (凸包+多边形面积)
- POJ 3348 Cows(凸包面积)
- Poj 3348 Cows (凸包面积)
- poj3348 Cows 凸包+多边形面积 水题
- Cows(poj3348凸包的面积)
- POJ 3348 Cows (凸包面积)
- POJ 3348 Cows (凸包面积)
- POJ 3348 Cows(凸包+多边形面积)
- POJ 3348 Cows(凸包面积)
- Windows下搭建Redis集群
- Python小练习
- jQuery选择器总结
- iptables --algo 字符串匹配算法 bm kmp
- iOS 对象数组的深拷贝(NSCoding协议)
- Cows(凸包面积)
- native.js 安卓自动连接制定名称和密码的wifi
- hihocoder-1526 序列的值(DP/二进制)
- 学习JPA
- 检查网络是否连接的工具类
- 将unsigned char字符串以16进制的字符串显示
- 122. Best Time to Buy and Sell Stock II
- 【openjudge】单词接龙
- Java基础(一)变量与运算