poj3348 Cows

题目描述:

vjudge

POJ

题解:

求凸包面积/50然后向下取整。

注意这个会WA:

poj3348 Cows
    double ans = S_(m);
    printf("%d\n",(int)(ans/50-0.5));
WA

这个可以AC:

poj3348 Cows
    double ans = S_(m)/50;
    printf("%d\n",(int)ans);
AC

代码:

poj3348 Cows
#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 10050;
struct Point
{
    double x,y;
    Point(){}
    Point(double x,double y):x(x),y(y){}
    Point operator - (const Point&a)const{return Point(x-a.x,y-a.y);}
    double operator ^ (const Point&a)const{return x*a.y-y*a.x;}
    bool operator < (const Point&a)const{return x!=a.x?x<a.x:y<a.y;}
};
typedef Point Vector;
int n;
Point p[N],s[N];
int build()
{
    sort(p+1,p+1+n);
    int tl = 0;
    for(int i=1;i<=n;i++)
    {
        while(tl>1&&((s[tl]-s[tl-1])^(p[i]-s[tl-1]))<=0)tl--;
        s[++tl] = p[i];
    }
    int k = tl;
    for(int i=n-1;i>=1;i--)
    {
        while(tl>k&&((s[tl]-s[tl-1])^(p[i]-s[tl-1]))<=0)tl--;
        s[++tl] = p[i];
    }
    if(tl>1)tl--;
    return tl;
}
double S_(int m)
{
    double ans = 0.0;
    for(int i=2;i<m;i++)
        ans += ((s[i]-s[1])^(s[i+1]-s[1]));
    return ans/2;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%lf%lf",&p[i].x,&p[i].y);
    int m = build();
    double ans = S_(m)/50;
    printf("%d\n",(int)ans);
    return 0;
}
View Code

 

上一篇:大数据概念


下一篇:一分钟了解大数据的价值