hdu4946-Area of Mushroom(凸包问题)

hdu4946-Area of Mushroom
Time Limit: 2000/1000 MS (Java/Others)   

题目链接如下:http://acm.hdu.edu.cn/showproblem.php?pid=4946

大意是说给你一些同学的坐标和他们的速度,谁最先走到某个地方这个地方就属于谁,问谁走出来的面积可以是无穷大。

step1:将速度最大值拎出来,其余点抛弃。

step2:坑1——如果最大速度为0,直接输出就ok了

step3:坑2——重点无法有无穷大面积(啧啧,真坑),但他又有可能出现在凸包线上,我们要给他标记出来

step4:用水平排序对其求凸包

坑2处理:

首先我们会这些点会进行水平排序,然后,我们标记无重点的点的flag[i]=0;有重点的我们标记第一个为flag[i]=1,其余重点为flag[i]=2;最后在结果输出的时候,我们需要对flag为0且在凸包上的点标记为1,其余不管全为0.完了


#include 
   
   
    
    
#include 
    
    
     
     
#include 
     
     
      
      
#include 
      
      
       
       
#include 
       
       
         #include 
        
          #define maxn 1000 using namespace std; const double eps = 1e-8,Pi=3.14159265; int n_,n; int flag[maxn]; int locat[maxn]={0};///位置函数,记录学生是0还是1 inline int dcmp(double x)///三态函数 { if(fabs(x) < eps) return 0; else return x>0 ? 1 : -1; } #define Vector Point struct Point { double x,y; int loc; inline Point(double x=0,double y=0):x(x),y(y) {} }p[maxn],ch[maxn]; bool myCmp(Point A, Point B) { if(A.x != B.x) return A.x < B.x; else return A.y < B.y; } Vector operator + (Vector A, Vector B) {return Vector(A.x + B.x, A.y + B.y);} Vector operator - (Vector A, Vector B) {return Vector(A.x - B.x, A.y - B.y);} bool operator == (const Vector& A, const Vector& B) {return dcmp(A.x-B.x)==0 && dcmp(A.y-B.y)==0;} inline double Cross(Vector A, Vector B)//叉积 { return A.x * B.y - A.y * B.x; } int ConvexHull() { int m = 0; for(int i = 0; i 
         
           1 && dcmp(Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2])) < 0) { m--; } ch[m++]=p[i]; if(flag[i]==1) ///如果这个点的flag为1,说明它也不可能为1,但是他又在凸包上,我们就要标记出来 { ch[m-1].loc=-1; } } int k = m; for(int i = n-2; i >= 0; i--) {///同上不赘述,求下凸包而已 if(flag[i]==2) continue; while(m > k && dcmp(Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2])) < 0) { m--; } ch[m++]=p[i]; if(flag[i]==1) { ch[m-1].loc=-1; } } if(n > 1) m--; return m; } double Dis(Point A, Point B) { return sqrt((A.x - B.x)*(A.x - B.x) + (A.y - B.y)*(A.y - B.y)); } int main() { int case_=1; int m , max_=-1; double py, px ; int a,b,speed,pi; while ( scanf ( "%d" , &n_ ) != EOF , n_ ){ memset(flag,0,sizeof(flag)); n=0;max_=-1; for(int i = 0; i < n_; i++) { cin>>a>>b>>speed; if(max_ <= speed){ if(max_ 
          
            =0)///排除flag[i]=0的情况 { locat[ch[i].loc]=1; } }///标记面积无穷点 printf("Case #%d: ",case_++); for(int i = 0; i < n_; i++) { if(locat[i]) { printf("1");locat[i]=0; } else { printf("0"); } } printf("\n"); } return 0; } 
           
          
         
       
      
      
     
     
    
    
   
   

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值