ZOJ-The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple-D
来源:互联网 发布:淘宝正品韩妆店铺贴吧 编辑:程序博客网 时间:2024/05/18 05:59
ACM模版
描述
题解
离散化找公共区间,然后对区间进行一定规则的累加就行了。
具体规则就看翻译了,能翻译对,就 AC,翻译不对,就可以洗洗碎了……还好猜样例猜到了规则!
哎,英语渣渣打比赛真是累~~~全靠猜!
对了,这个题的数据有些迷,题目说好了
代码
#include <iostream>#include <algorithm>#include <cstring>using namespace std;const int MAXN = 200;struct Node{ int l; int r;} AtoB[MAXN], BtoA[MAXN];int pos[MAXN * 4], pos_[MAXN * 4], vis[MAXN * 4], vis_[MAXN * 4];int bs(int l, int r, int k){ while (l < r) { int m = (l + r) / 2; if (k <= pos_[m]) { r = m; } else { l = m + 1; } } return l;}int main(){// freopen("/Users/zyj/Desktop/input.txt", "r", stdin); int T; cin >> T; while (T--) { memset(vis, 0, sizeof(vis)); memset(vis_, 0, sizeof(vis_)); int n, m, x, y; cin >> n >> m >> x >> y; int cnt = 0; for (int i = 0; i < x; i++) { cin >> AtoB[i].l >> AtoB[i].r; pos[cnt++] = AtoB[i].l; pos[cnt++] = AtoB[i].r; } for (int i = 0; i < y; i++) { cin >> BtoA[i].l >> BtoA[i].r; pos[cnt++] = BtoA[i].l; pos[cnt++] = BtoA[i].r; } sort(pos, pos + cnt); int cnt_ = 0; for (int i = 1; i < cnt; i++) { if (pos[i] != pos[i - 1]) { pos[++cnt_] = pos[i]; } } cnt = 0; for (int i = 0; i <= cnt_; i++) { pos_[cnt++] = pos[i] * 2; pos_[cnt++] = pos[i] * 2 + 1; } for (int i = 0; i < x; i++) { int l = bs(0, cnt, AtoB[i].l * 2); int r = bs(0, cnt, AtoB[i].r * 2); for (int j = l; j <= r; j++) { vis[j] = 1; } } for (int i = 0; i < y; i++) { int l = bs(0, cnt, BtoA[i].l * 2); int r = bs(0, cnt, BtoA[i].r * 2); for (int j = l; j <= r; j++) { vis_[j] = 1; } } for (int i = 0; i < cnt; i++) { vis[i] = min(vis[i], vis_[i]); } int ans = 0; int i = 0; while (i < cnt) { int j = i; while (vis[i]) { i++; } if ((pos_[i - 1] - pos_[j]) / 2 + 1 >= m) { ans += (pos_[i - 1] - pos_[j]) / 2 + 1 - m + 1; } i++; } cout << ans << endl; } return 0;}
1 1
- ZOJ-The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple-D
- ZOJ-The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple-E
- ZOJ-The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple-A~B
- ZOJ-The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple-C
- The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple(A+B+C+D)
- The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple C题What Kind of Fri
- The 12th Zhejiang Provincial Collegiate Programming Contest - D
- The 14th Zhejiang Provincial Collegiate Programming Contest (待续)
- The 17th Zhejiang University Programming Contest Sponsored by TuSimple 浙大校赛C题 How Many Nines
- ZOJ 146 - The 13th Zhejiang Provincial Collegiate Programming Contest - C Defuse the Bomb
- The 9th Zhejiang Provincial Collegiate Programming Contest->Problem D:D - Draw Something Cheat
- The 9th Zhejiang Provincial Collegiate Programming Contest->Problem D:D - Draw Something Cheat
- The 7th Zhejiang Provincial Collegiate Programming Contest
- The 6th Zhejiang Provincial Collegiate Programming Contest
- The 8th Zhejiang Provincial Collegiate Programming Contest / L - Javabeans
- The 8th Zhejiang Provincial Collegiate Programming Contest / M - Median
- The 8th Zhejiang Provincial Collegiate Programming Contest
- The 9th Zhejiang Provincial Collegiate Programming Contest
- 51Nod 1082 与7无关的数
- 用XGBoost做时间序列预测—forecastxgb包
- 备考PMP第五天
- HDu 6000 Wash(贪心)
- 精英特速读记忆:记忆方法集锦
- ZOJ-The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple-D
- Go实现控制任程序的生命周期
- 推荐两个不错的国内UI编辑器
- 浙江省赛C题 What Kind of Friends Are You?
- Nginx 源码阅读笔记7 worker 主循环
- Java 反射机制小结
- Collection集合集成结构图图
- Linux 命令行报错:-bash:XXX: command not found ,解决方法参考
- android之资源命名索引