时间: 2020-11-26|51次围观|0 条评论

题目描述:

vjudge

POJ

题解:

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

注意这个会WA:

poj3348 Cows插图
poj3348 Cows插图1

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

WA

这个可以AC:

poj3348 Cows插图
poj3348 Cows插图1

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

AC

代码:

poj3348 Cows插图
poj3348 Cows插图1

#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

 

转载于:https://www.cnblogs.com/LiGuanlin1124/p/10983037.html

原文链接:https://blog.csdn.net/weixin_30342827/article/details/99152747

本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

本博客所有文章如无特别注明均为原创。
复制或转载请以超链接形式注明转自起风了,原文地址《poj3348 Cows
   

还没有人抢沙发呢~