poj 3348(凸包面积)

Cows

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

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

题意:在一个树林里面养牛,每头牛需要50平方米的空间,问你总共可以养多少牛?题解:凸包面积/50
#include <iostream>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
using namespace std;
const int N = 10005;
const double eps = 1e-8;
struct Point {
    int x,y;
}p[N],Stack[N];
int n;
int cross(Point a,Point b,Point c){
    return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);
}
double getarea(Point a,Point b,Point c){
    return cross(a,b,c)/2.0;
}
double dis(Point a,Point b){
    return  sqrt((double)((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)));
}
int cmp(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;
}
int Graham(){
    int k=0;
    for(int i=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);
    int top =2;
    Stack[0] = p[0];
    Stack[1] = p[1];
    Stack[2] = p[2];
    for(int i=3;i<n;i++){
        while(top>=1&&cross(p[i],Stack[top],Stack[top-1])>=0) top--;
        Stack[++top] = p[i];
    }
    double area = 0;
    for(int i=1;i<top;i++){
        area+=getarea(Stack[i],Stack[i+1],Stack[0]); ///这里打成p..WA了几次..
    }
    return floor(area/50);
}
int main()
{
    while(scanf("%d",&n)!=EOF){
        for(int i=0;i<n;i++){
            scanf("%d%d",&p[i].x,&p[i].y);
        }
        if(n==1||n==2) {
            printf("0\n");
            continue;
        }
        int ans =  Graham();
        printf("%d\n",ans);
    }
    return 0;
}
时间: 2024-07-29 00:32:01

poj 3348(凸包面积)的相关文章

POJ 3348 Cows 凸包 求面积

LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileName: POJ 3348 凸包面积 叉积.cpp * @Platform: Windows * @Author : Lweleth ([email protected]) * @Link : https://github.com/ * @Version : $Id$ */ #include <std

poj 3348 Cow 凸包面积

Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8122   Accepted: 3674 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 f

POJ 3348 Cows(凸包面积)

Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7515   Accepted: 3418 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 f

poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207

Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7038   Accepted: 3242 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 f

POJ 3348

水题.不过,题意..呵呵了.. 围一个凸包,求出面积,然后除以50就可以了. #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> using namespace std; const int MAXN=10500; struct point { int x,y; }p[MAXN]; int n; int ans[MAXN],st[MAXN]; int stop

poj 1113 凸包周长

Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 33888   Accepted: 11544 Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King's castle. The King was so greedy, that he w

poj 1873 凸包+枚举

The Fortified Forest Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6198   Accepted: 1744 Description Once upon a time, in a faraway land, there lived a king. This king owned a small collection of rare and valuable trees, which had been

poj 1265 Area 面积+多边形内点数

Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5861   Accepted: 2612 Description Being well known for its highly innovative products, Merck would definitely be a good target for industrial espionage. To protect its brand-new resear

POJ 2079 凸包最大内接三角形

Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 8038   Accepted: 2375 Description Given n distinct points on a plane, your task is to find the triangle that have the maximum area, whose vertices are from the given points. Input