Mr. X and His Shots

题目链接

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 100010;

struct Line {
    int s, e;
    Line() { }
    Line(int _s, int _e) : s(_s), e(_e) { }
    bool operator < (const Line &l) {
        if(s == l.s) return e < l.e;
        return s < l.s;
    }
};
vector<Line> v1, v2;

int check(const Line &l1, const Line &l2) {
    if(l1.e < l2.s) return -1;
    if(l1.s > l2.e) return 1;
    return 0;
}

int main() {

    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    int n, m;
    int ans;
    Line l;
    ans = 0;
    scanf("%d %d", &n, &m);
    for(int i = 0; i < n; ++i) {
        scanf("%d %d", &l.s, &l.e);
        if(l.s > l.e) swap(l.s, l.e);
        v1.push_back(l);
    }
    for(int i = 0; i < m; ++i) {
        scanf("%d %d", &l.s, &l.e);
        if(l.s > l.e) swap(l.s, l.e);
        v2.push_back(l);
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    int id1 = 0, id2 = 0;
    while(id1 < n && id2 < m) {
        if(v2[id2].e < v1[id1].s) {
            id2++;
        } else if(v1[id1].e < v2[id2].s) {
            id1++;
        } else {
            int tid = id1;
            while(tid < n && check(v1[tid], v2[id2]) != 1) {
                if(check(v1[tid], v2[id2]) == 0) ans++;
                tid++;
            }
            id2++;
        }
    }
    printf("%d\n", ans);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值