Cows

Cows

Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 6   Accepted Submission(s) : 4
Problem 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
4
0 0
0 101
75 0
75 101
 

 

Sample Output
151
 

 

Source
PKU
 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <math.h>
 4 #include <string.h>
 5 #define eps 1e-8
 6 typedef struct point{int x,y;}point;
 7 int compd(const void *a,const void  *b)
 8 {
 9     return (((point*)b)->x-((point*)a)->x)*(-1);
10 }
11 
12 //计算多边形面积,顶点按顺时针或逆时针给出
13 int area_polygon(int n,point* p)
14 {
15     int s1=0,s2=0;
16     int i;
17     for (i=0;i<n;i++)
18         s1+=p[(i+1)%n].y*p[i].x,s2+=p[(i+1)%n].y*p[(i+2)%n].x;
19     return fabs(s1-s2)/2;
20 }
21 
22 int mult(point sp, point ep, point op)
23 {
24   return (sp.x - op.x) * (ep.y - op.y) >= (ep.x - op.x) * (sp.y - op.y);
25 }
26 int graham(point pnt[], int n, point res[])
27 {
28     int i, len, k = 0, top = 1;
29     qsort(pnt, n, sizeof(point), compd);//递增排序
30     if (n == 0) return 0; res[0] = pnt[0];
31     if (n == 1) return 1; res[1] = pnt[1];
32     if (n == 2) return 2; res[2] = pnt[2];
33     for (i = 2; i < n; i++)
34     {
35         while (top && mult(pnt[i], res[top], res[top-1]))
36             top--;
37         res[++top] = pnt[i];
38     }
39     len = top; res[++top] = pnt[n - 2];
40     for (i = n - 3; i >= 0; i--)
41     {
42         while (top!=len && mult(pnt[i], res[top],
43             res[top-1])) top--;
44         res[++top] = pnt[i];
45     }
46     return top;
47 }
48 
49 int main()
50 {
51    int T,i,j,Len;
52    int Sign,NUM,x,y,X,Y;
53    point ID[50100],STR[10100];
54    scanf("%d",&T);
55    for(i=0;i<T;i++)
56         scanf("%d%d",&ID[i].x,&ID[i].y);
57     Len=graham(ID,T,STR);
58     Sign=area_polygon(Len,STR);
59   /*  for(i=0,Sign=0;i<Len;i++)
60     {
61         Sign+=(STR[(i+1)%Len].x*STR[i].y)-(STR[(i+1)%Len].y*STR[i].x);
62         printf("%d %d\n",STR[i].x,STR[i].y);  
63    }*/
64     Sign=Sign>0?Sign:-Sign;
65     printf("%d\n", Sign/50);
66     return 0;
67 }
View Code

 

posted @ 2014-08-22 13:56  Wurq  阅读(233)  评论(0编辑  收藏  举报