hdu 2907 凹陷面

给定一个多边形,让你求出其价值。价值的定义是:-p*凹面的个数+q*凸面的个数。。。最小值为0

凸面的个数就是凸包中的点的个数,但是当出现凹面时,就会减少一个凸面,这是因为这时候的凸面是虚拟出来的!!!!!

题意参考这里 点击打开链接


int  cmp(double x){
     if(fabs(x) < 1e-8) return 0 ;
     if(x > 0) return 1 ;
     return -1  ;
}

struct point{
       double  x ,  y  ;
       int  id ;
       point(){}
       point(double _x , double _y):x(_x) , y(_y){}
       friend bool operator == (const point &a , const point &b){
              return cmp(a.x - b.x) == 0 && cmp(a.y - b.y) == 0 ;
       }
       friend double operator ^ (const point &a , const point &b){
              return a.x * b.y - a.y * b.x ;
       }
       friend double dist(const  point &a , const point &b){
              return  sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) ) ;
       }
       point operator - (point o){
             return  point(x - o.x , y - o.y) ;
       }
};


bool  cmpless(const  point &a , const point &b){
      return   cmp(a.x - b.x) < 0
            || cmp(a.x - b.x == 0) && cmp(a.y - b.y) < 0 ;
}

vector<point> convex_hull(vector<point> a){
     vector<point> src(2 * a.size() + 5)  ;
     sort(a.begin() , a.end() , cmpless) ;
     a.erase(unique(a.begin() , a.end()) , a.end())  ;
     int m = 0 ;
     for(int i = 0 ; i < a.size() ; i++){
          while(m > 1 && cmp( (src[m-1] - src[m-2]) ^  (a[i] - src[m-2]) ) <= 0)
              m-- ;
          src[m++] = a[i] ;
     }
     int k = m ;
     for(int i = a.size() - 2 ; i >= 0 ; i--){
          while(m > k && cmp( (src[m-1] - src[m-2]) ^ (a[i] - src[m-2])) <= 0)
              m-- ;
          src[m++] = a[i] ;
     }
     src.resize(m) ;
     if(a.size() > 1) src.resize(m-1) ;
     return src ;
}

int   vis[38] ;

int   main(){
      int n  ,  i  , t  , pcnt , qcnt , p , q ;
      cin>>t  ;
      while(t--){
           cin>>p>>q>>n ;
           vector<point> lis(n) ;
           for(i = 0 ; i < n ; i++){
                scanf("%lf%lf" , &lis[i].x , &lis[i].y) ;
                lis[i].id = i ;
           }

           vector<point> hull = convex_hull(lis) ;
           qcnt = hull.size() ;

           memset(vis , 0 , sizeof(vis)) ;
           for(i = 0 ; i < hull.size() ; i++) vis[hull[i].id] = 1 ;

           pcnt = 0 ;
           for(i = 0 ; i < n ; i++){
                if(vis[i] && !vis[(i+1)%n]) pcnt++ ;
           }
           qcnt -= pcnt ;

           cout<< max(0 , q * qcnt - p * pcnt )<< endl ;
      }
      return  0  ;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值