【Codeforces 469B】Chat Online

【链接】 我是链接,点我呀:)
【题意】

【题解】

因为你的朋友的时间是固定的. 你完全可以开一个tag[50]的数组,如果tag[i]=1说明i时刻你的基友在线(扫描基友的时间就能

得到
然后你在判断有没有交集的时候,只要把你的时间扫描一遍,看看有没有tag==1的位置就好了
有的话就说明有机会可以和你的基友聊天.

【代码】

#include <bits/stdc++.h>
#define rep1(i,a,b) for (int i = a;i <= b;i++)

using namespace std;

const int N = 50;

int p,q,l,r;
int a[N+10][2],b[N+10][2];
int tag[3000];

int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> p >> q >> l >> r;
    rep1(i,1,p){
        rep1(j,0,1)
            cin >> a[i][j];
        rep1(j,a[i][0],a[i][1]) tag[j] = 1;
    }
    rep1(i,1,q)
        rep1(j,0,1)
            cin >> b[i][j];
    int ans = 0;
    rep1(i,l,r){
        bool ok = false;
        rep1(j,1,q){
            rep1(k,b[j][0],b[j][1])
                if (tag[i+k])
                    ok = true;
        }
        if (ok) ans++;
    }
    cout<<ans<<endl;
    return 0;
}
原文地址:https://www.cnblogs.com/AWCXV/p/9741845.html