LA 6263 The Dragon and the knights 平面划分 ,欧拉定理

题目地址:LA6263

首先对于直线将平面划分为多少个区域,有平面上的欧拉定理。

F=E-V+1   (不是2)

然后统计每一对相交的直线(因为没有三点共线) ,对E+=2,V++;

关键的是判断每一个点关于直线的方位“标示符”,这里是一个长度为n的二进制数,n<=100  ,用两个long long 存储就好了  如果用vector存贮会超时(比较时),

然后取unique,得到点分布的区域数,和欧拉定理得到的区域数进行比较就行了。

注意:超int 要用long long。

代码:

#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;

const double eps=1e-8;



struct  Point
{
    long long x;
    long long y;
    Point(long long  x=0, long long y=0) :x(x),y(y) {}
    
};

typedef  Point Vector;

Point p[50005];
Point inter[10000];
long  long   a[105],b[105],c[105];

int n,m;
//vector<int> v[50005];

bool vector_cmp(vector<int> a,vector<int> b)
{
    int sz=a.size();
    for(int i=0;i<sz;i++)
    {
        if(a[i]<b[i]) return 1;
        else if(a[i]>b[i])    return 0;
        
    }
    
    return 0;
    
}


int getBit(long long  a,long long  b,long long  c,Point  p)
{
    if(a*p.x+b*p.y+c>0)  return 1;
    else return 0;
}


struct  status
{
    long long a;
    long long b;
    status(long long a=0,long long b=0):a(a),b(b){}
    
};

status s[50005];

bool status_cmp(status A,status B)
{
    if(A.a<B.a) return 1;
    else if(A.a==B.a)
    {
        if(A.b<B.b) return 1;
        else return 0;
    }
    else return 0;
}

bool operator==(status A,status B)
{
    if(A.a==B.a&&A.b==B.b)  return 1;
    else return  0;
    
}
long long  Cross(Vector A,Vector B)
{
    return A.x*B.y-A.y*B.x;
    
}
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        cin>>n>>m;
        for(int i=0;i<n;i++)
        {
            scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
        }
        
        for(int i=0;i<m;i++)
        {
            scanf("%lld%lld",&p[i].x,&p[i].y);
        }
        
//        for(int i=0;i<m;i++)
//        {
//            for(int j=0;j<n;j++)
//            {
//                v[i].push_back(getBit(a[j], b[j], c[j], p[i]));
//                
//            }
//        }
        
        
        for(int i=0;i<m;i++)
        {
            s[i].a=0;
            s[i].b=0;
            if(n<=50)
                for(int j=0;j<n;j++)
                {
                    s[i].a=2*s[i].a+getBit(a[j], b[j], c[j], p[i]);
                }
            
            else
            {
                for(int j=0;j<50;j++)
                {
                    s[i].a=2*s[i].a+getBit(a[j], b[j], c[j], p[i]);
                }
                for(int j=50;j<n;j++)
                {
                    s[i].b=2*s[i].b+getBit(a[j], b[j], c[j], p[i]);
                }
            }
        }
        
        
        
        sort(s,s+m,status_cmp);
        
        long long  protected_region =unique(s,s+m)-s;
//        sort(v,v+m,vector_cmp);
//        
//        int protected_region =unique(v,v+m)-v;
        
       
        
        long long  V=0,F=0,E=n;
        
        int cnt=0;
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                if(Cross(Vector(a[i],b[i]), Vector(a[j],b[j]))!=0)
                {
                    E+=2;
                    V++;
                }
            }
        }
        
        F=E-V+1;
        
       // cout<<F<<' '<<protected_region<<endl;
        if(F==protected_region)  cout<<"PROTECTED"<<endl;
        else cout<<"VULNERABLE"<<endl;
        
    }
    
}




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值