Codeforces Round #268 (Div. 2) B

来源:互联网 发布:淘宝女童模特章露雅 编辑:程序博客网 时间:2024/05/16 12:27

题意分析:

B. Chat Online
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Little X and Little Z are good friends. They always chat online. But both of them have schedules.

Little Z has fixed schedule. He always online at any moment of time between a1 and b1, between a2 and b2, ..., between ap and bp (all borders inclusive). But the schedule of Little X is quite strange, it depends on the time when he gets up. If he gets up at time 0, he will be online at any moment of time between c1 and d1, between c2 and d2, ..., between cq and dq (all borders inclusive). But if he gets up at time t, these segments will be shifted by t. They become [ci + t, di + t] (for all i).

If at a moment of time, both Little X and Little Z are online simultaneosly, they can chat online happily. You know that Little X can get up at an integer moment of time between l and r (both borders inclusive). Also you know that Little X wants to get up at the moment of time, that is suitable for chatting with Little Z (they must have at least one common moment of time in schedules). How many integer moments of time from the segment [l, r] suit for that?

Input

The first line contains four space-separated integers p, q, l, r (1 ≤  p, q ≤ 50; 0 ≤ l ≤ r ≤ 1000).

Each of the next p lines contains two space-separated integers ai, bi (0 ≤ ai < bi ≤ 1000). Each of the next q lines contains two space-separated integers cj, dj (0 ≤ cj < dj ≤ 1000).

It's guaranteed that bi < ai + 1 and dj < cj + 1 for all valid i and j.

Output

Output a single integer — the number of moments of time from the segment [l, r] which suit for online conversation.

Sample test(s)
input
1 1 0 42 30 1
output
3
input
2 3 0 2015 1723 261 47 1115 17
output
20

题意分析:

给出z这个人上网的时间段。然后给出a的时间段,a起床时间在一个区间,然后他的时间段都要加上起床时间。a的区间跟z的区间重叠一次他们就开心了,求他们能happy的总数。
按着起床区间一个一个枚举,然后判断一下区间是否重合就行了。

代码:

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define REP(i, s, t) for(int (i)=(s);(i)<=(t);++(i))#define REPOK(i, s, t, o) for(int (i)=(s);(i)<=(t) && (o);++(i))struct node{    int l;    int r;    node() {};    node(int l, int r):l(l),r(r) {};};int p, q, l, r, t;node x[105];node z[105];int main(){    scanf("%d%d%d%d",&p,&q,&l,&r);    int a, b;    REP(i, 0, p-1)    {        cin >> a >> b;        z[i] = node(a, b);    }    REP(i, 0, q-1)    {        cin >> a >> b;        x[i] = node(a, b);    }    int cnt = 0;    REP(k, l, r)    {        int t = k;        bool ok = true;        REPOK(i, 0, p-1, ok)        REPOK(j, 0, q-1, ok)        {            if (z[i].r < x[j].l+t)                continue;            if (z[i].l > x[j].r+t)                continue;            ok = false;        }        if (!ok)            ++cnt;    }    cout << cnt << endl;    return 0;}


0 0
原创粉丝点击