Codeforces Round #268 (Div. 2) B
来源:互联网 发布:淘宝女童模特章露雅 编辑:程序博客网 时间:2024/05/16 12:27
题意分析:
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?
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 a single integer — the number of moments of time from the segment [l, r] which suit for online conversation.
1 1 0 42 30 1
3
2 3 0 2015 1723 261 47 1115 17
20
题意分析:
代码:
#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;}
- Codeforces Round #268 (Div. 2) B
- Codeforces Round #268 (Div. 1) B
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #134 (Div. 2)B. Airport
- Codeforces Round #170 (Div. 2) problem B
- Codeforces Round #173 (Div. 2) Problem B
- Codeforces Round #181 (Div. 2) B. Coach
- Codeforces Round #185 (Div. 2)--A,B
- Codeforces Round #171 (Div. 2) B
- Codeforces Round #169 (Div. 2) B题
- Codeforces Round #188 (Div. 2) B题
- Codeforces Round #192 (Div. 2) B
- Codeforces Round #203 (Div. 2) B. Resort
- Codeforces Round #206 (Div. 2) - b
- Codeforces Round #202 (Div. 2)B-贪心
- Codeforces Round #203 (Div. 2)B
- Codeforces Round #203(Div. 2)B. Resort
- Codeforces Round #206 (Div. 2)B
- 2015面试题目集锦
- 4.10 服务器上的 Git - Git 托管服务
- exynos4412启动流程
- NYOJ 311 完全背包
- C++中野指针问题分析总结
- Codeforces Round #268 (Div. 2) B
- Mybatis if test中字符串比较
- TCP协议的TIME_WAIT状态详解
- 【面向切面编程_AOP】
- flume-ng+Kafka+Storm+HDFS 实时系统搭建
- 《Unix NetWork Programming》(Unix网络编程)—环境搭建
- 5.1 分布式 Git - 分布式工作流程
- 利用Excel制作问卷的柱形图
- UVa 10828 - Back to Kernighan-Ritchie (概率DP 期望 高斯消元)