HDU2907

来源:互联网 发布:linux 安装squid 编辑:程序博客网 时间:2024/06/07 04:08
代码还是WA的。还是没有处理好判断
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;const double eps=1e-10;int dcmp(double x){    if(fabs(x)<eps) return 0;    return x<0?-1:1;}struct Point{    double x,y;    Point(){}    Point(double x,double y):x(x),y(y){}    bool operator==(const Point& rhs)const    {        return dcmp(x-rhs.x)==0 && dcmp(y-rhs.y)==0;    }    bool operator<(const Point& rhs)const    {        return dcmp(x-rhs.x)<0 || (dcmp(x-rhs.x)==0 && dcmp(y-rhs.y)<0);    }};typedef Point Vector;Vector operator-(Point A,Point B){    return Vector(A.x-B.x,A.y-B.y);}double Cross(Vector A,Vector B){    return A.x*B.y-A.y*B.x;}double Length(Point A,Point B){    return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));}int ConvexHull(Point *p,int n,Point *ch)//Çó͹°ü{    sort(p,p+n);    n=unique(p,p+n)-p;    int m=0;    for(int i=0;i<n;i++)    {        while(m>1 && Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2])<0) m--;        ch[m++]=p[i];    }    int k=m;    for(int i=n-2;i>=0;i--)    {        while(m>k && Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2])<0) m--;        ch[m++]=p[i];    }    if(n>1) m--;    return m;}const int maxn=34;int n,t,_p,q;Point p[maxn],poly[maxn];int main(){    scanf("%d",&t);    while(t--){        scanf("%d%d%d",&_p,&q,&n);        for(int i=0;i<n;i++){            scanf("%lf%lf",&p[i].x,&p[i].y);        }        reverse(p,p+n);        sort(p,p+n);        int m=ConvexHull(p,n,poly);        int a=0,b=0,cnt=0;        //if(p[0]==poly[0])printf("hahahahha\n");        for(int i=0;i<n;i++){            if(p[i]==poly[cnt]&&p[(i+1)%n]==poly[(cnt+1)%m]){                b++;cnt++;            }            else if(p[i]==poly[cnt]&&!(p[(i+1)%n]==poly[(cnt+1)%m])){                i++;a++;            }        }        int ans=-a*_p+b*q;        printf("%d\n",ans>0?ans:0);    }    return 0;}

0 0
原创粉丝点击