Cows
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 4 0 0 0 101 75 0 75 101 Sample Output 151 Source
CCC 2007
|
题目:http://poj.org/problem?id=3348
题意:给你n个点,求这n个点构成的凸包的面积所能容纳牛的头数
分析:求凸包完后用多边形面积公式求出面积即可
代码:
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; const int mm=11111; typedef int mType; struct Tpoint { mType x,y; Tpoint(){} Tpoint(mType _x,mType _y):x(_x),y(_y){} }g[mm],q[mm]; Tpoint MakeVector(Tpoint P,Tpoint Q) { return Tpoint(Q.x-P.x,Q.y-P.y); } mType CrossProduct(Tpoint P,Tpoint Q) { return P.x*Q.y-P.y*Q.x; } mType MultiCross(Tpoint P,Tpoint Q,Tpoint R) { return CrossProduct(MakeVector(Q,P),MakeVector(Q,R)); } mType SqrDis(Tpoint P,Tpoint Q) { return (P.x-Q.x)*(P.x-Q.x)+(P.y-Q.y)*(P.y-Q.y); } bool TurnRight(Tpoint P,Tpoint Q,Tpoint R) { mType tmp=MultiCross(P,Q,R); if(tmp>0)return 1; if(tmp<0)return 0; return SqrDis(P,Q)<SqrDis(P,R); } bool cmp(Tpoint P,Tpoint Q) { return TurnRight(g[0],Q,P); } void Graham(int n,int &m) { int i,j; for(j=i=0;i<n;++i) if(g[i].x<g[j].x||(g[i].x==g[j].x&&g[i].y<g[j].y))j=i; swap(g[0],g[j]); sort(g+1,g+n,cmp); q[m=0]=g[n]=g[0]; for(i=1;i<=n;++i) { while(m&&TurnRight(q[m-1],q[m],g[i]))--m; q[++m]=g[i]; } } int main() { int i,n,m,ans; while(~scanf("%d",&n)) { for(i=0;i<n;++i) scanf("%d%d",&g[i].x,&g[i].y); Graham(n,m); for(ans=i=0;i<m;++i) ans+=CrossProduct(q[i],q[i+1]); printf("%d\n",ans/100); } return 0; }