POJ 3348 (convex bag area)

Source: Internet
Author: User

Cows
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 8063 Accepted: 3651

Description

Your friend to the south was interested in building fences and turning plowshares into swords. In order to help with his overseas adventure, they is forced to the save money on buying fence posts by using trees as fence Posts wherever possible. Given the locations of some trees, you be to help farmers a try to create the largest pasture this is possible. Not all the trees would need to be used.

However, because you'll oversee the construction of the pasture yourself, all the farmers want to know are how many cows They can put in the pasture. It is the well known, a cow needs at least 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 tha T grow on the available land. The next n lines contain the integer coordinates of each tree given as the integers x and y Sep Arated by one space (Where-1000≤x, y≤1000). The integer coordinates correlate exactly to distance in metres (e.g., the distance between coordinate (ten;) and (11; 1 1) is one metre).

Output

You is to output a single integer value and the number of cows that can survive in the largest field you can construct using The available trees.

Sample Input

40 00 10175) 075 101

Sample Output

151

Test instructions: In a forest to raise cattle, each cow needs 50 square meters of space, ask you how many cows can be raised?
Puzzle: Convex bag Area/50
#include <iostream>#include<cstdio>#include<cstring>#include<math.h>#include<algorithm>#include<stdlib.h>using namespacestd;Const intN =10005;Const DoubleEPS = 1e-8;structPoint {intx, y;} P[n],stack[n];intN;intCross (Point A,point b,point c) {return(a.x-c.x) * (B.Y-C.Y)-(A.Y-C.Y) * (b.x-c.x);}DoubleGetarea (Point a,point b,point c) {returnCross (A,B,C)/2.0;}DoubleDis (point a,point b) {returnsqrt ((Double) ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-B.Y))) ;}intCMP (point A,point b) {if(Cross (a,b,p[0]) >0)return 1; if(Cross (a,b,p[0])==0&&dis (b,p[0])-dis (a,p[0]) >eps)return 1; return 0;}intGraham () {intk=0;  for(intI=1; i<n;i++){        if(p[i].y<p[k].y| | (P[I].Y==P[K].Y) && (p[i].x<p[k].x)) k=i; } Swap (p[0],p[k]); Sort (P+1, p+n,cmp); inttop =2; stack[0] = p[0]; stack[1] = p[1]; stack[2] = p[2];  for(intI=3; i<n;i++){         while(top>=1&&cross (p[i],stack[top],stack[top-1]) >=0) top--; stack[++top] =P[i]; }    DoubleArea =0;  for(intI=1; i<top;i++) { area+=getarea (stack[i],stack[i+1],stack[0]);///this is called P. WA a few times .    }    returnFloor (area/ -);}intMain () { while(SCANF ("%d", &n)! =EOF) {         for(intI=0; i<n;i++) {scanf ("%d%d",&p[i].x,&p[i].y); }        if(n==1|| n==2) {printf ("0\n"); Continue; }        intAns =Graham (); printf ("%d\n", ans); }    return 0;}

POJ 3348 (convex bag area)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.