The Dragon and the knights

题目链接:http://codeforces.com/gym/100624/attachments

题目大意:在二维平面,有n条直线将平面划分成若干各区域,有m个点,问是不是在每个区域都至少存在一个点? n<=100  m<= 50000,保证没有三条直线交于同一点,没有两条相同的直线!

解题思路:先暴力的算出有多少个区域:假设已经有了i 条直线,现在算第i+1 条直线划分下去将增加多少区域,其实就是前i 条直线里面与第 i+1 条直线相交的个数+1 。

然后,对于每一个点算出它在每一条直线的左边还是右边(左边用0表示 右边用1 表示),用两个long long 来存,然后数一下有多少个所在区域不同的点,与区域数目进行比较


我写错的地方是:第一,一开始我用string 表示的01串;第二,1<<50是会爆掉int的,必须写成 1LL<<50。(太久没有写代码了。。。。)

//#pragma comment(linker,"/STACK:102400000,102400000")
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define ll long long
#define db double
#define PB push_back
#define lson k<<1
#define rson k<<1|1
using namespace std;


const int N = 105;
const int M = 50005;
const db eps = 1e-8;


struct Point
{
    ll x, y;
    Point(db _x = 0, db _y = 0): x(_x), y(_y) {}
    void input()
    {
        scanf("%I64d%I64d", &x, &y);
    }
    db operator * (const Point &t) const
    {
        return x * t.y - y * t.x;
    }
    Point operator - (const Point &t) const
    {
        return Point(x - t.x, y - t.y);
    }
} p[M];


struct Line
{
    ll a, b, c;
    void input()
    {
        scanf("%I64d%I64d%I64d", &a, &b, &c);
    }
} l[N];


bool parallel(const Line &l1, const Line &l2)
{
    return l1.a * l2.b == l1.b * l2.a;
}
int n, m;


const int BASE = 50;
struct node
{
    ll a[2];
    node()
    {
        a[0] = a[1] = 0LL;
    }
    void setbit(int k)
    {
        a[k / BASE] |= 1LL << (k % BASE);
    }
    void setzero()
    {
        a[0] = a[1] = 0LL;
    }
    bool operator < (const node &t) const
    {
        return a[0] < t.a[0] || (a[0] == t.a[0] && a[1] < t.a[1]);
    }
} seq[M];


int main()
{
#ifdef PKWV
    freopen("in.in", "r", stdin);
#endif // PKWV
    int T;
    scanf("%d", &T);
    while(T--)
    {
        scanf("%d%d", &n, &m);
        int numb(0);
        for(int i = 0; i < n; i++)
        {
            l[i].input();
            int cnt(0);
            for(int j = 0; j < i; j++)
                if(!parallel(l[i], l[j])) cnt++;
            numb += cnt + 1;
        }
        numb += 1;
        for(int i = 0; i < m; i++)
        {
            p[i].input();
            seq[i].setzero();
            for(int j = 0; j < n; j++)
            {
                ll k = p[i].x * l[j].a + p[i].y * l[j].b + l[j].c;
                if(k > 0) seq[i].setbit(j);
            }
        }
        sort(seq, seq + m);
        int cnt(1);
        for(int i = 1; i < m; i++)
            if(seq[i].a[0] != seq[i - 1].a[0] || seq[i].a[1] != seq[i - 1].a[1]) cnt++;
        if(cnt == numb) printf("PROTECTED\n");
        else printf("VULNERABLE\n");
    }
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值