ZOJ 3953-贪心
2017-08-16 10:54
344 查看
题目链接
对区间的左端点进行排序,然后每三个点进行一次判断,如果出现两两相交的情况就删除右端点值最大的那个区间
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <string> #include <string.h> #include <cmath> #include <sstream> #include <set> #include <map> #include <functional> #include <queue> #include <vector> using namespace std; const int maxn = 50010; int t, n; struct N { int l, r, id; bool operator<(const N& a) const { return l < a.l; } }Num[maxn], temp[3]; bool cmp_r(N a, N b) { return a.r > b.r; } bool cmp_r2(N a, N b) { return a.r < b.r; } int main() { cin >> t; while (t--) { cin >> n; for (int i = 1; i <= n; i++) { cin >> Num[i].l >> Num[i].r; Num[i].id = i; } sort(Num + 1, Num + 1 + n); vector<int> res; res.clear(); for (int i = 1, num = 0; i <= n; i++) { sort(temp, temp + num, cmp_r); if (num&&temp[num-1].r < Num[i].l)//如果不相交 num--; temp[num++] = Num[i]; if (num == 3) { sort(temp, temp + 3, cmp_r2); res.push_back(temp[2].id); num--; } } sort(res.begin(), res.end()); cout << res.size() << endl; for (int i = 0; i < res.size(); i++) { if (i == res.size() - 1) cout << res[i] << endl; else cout << res[i] << " "; } cout << endl; } }
相关文章推荐
- ZOJ - 3953 Intervals(贪心)
- ZOJ-3953-Intervals 贪心
- ZOJ 3953 Intervals(区间贪心)
- 浙大17年校赛(ZOJ 3953) Intervals[贪心]
- ZOJ 3953 Intervals (贪心/区间交)
- ZOJ3953 ZJU2017校赛(贪心)
- ZOJ-3953-Intervals【贪心】【17th浙大校赛】
- ZOJ3953 Intervals 【贪心 双线程活动分配问题】
- ZOJ 3953 Intervals (贪心)
- ZOJ 3953 贪心+优先队列
- zoj3953 贪心 training 3
- ZOJ 2921 Stock(贪心)
- zoj 2921 Stock(贪心)
- ZOJ-3987 Numbers 2017CCPC秦皇岛站G题 (二进制、贪心)
- ZOJ-3778-Talented Chef【11th浙江省赛】【贪心】
- ZOJ FatMouse' Trade 贪心
- 贪心,二叉树搜索,ZOJ(2315)
- ZOJ 3946 Highway Project【dijkstra】【贪心】
- ZOJ 1076Gene Assembly(很简单的贪心)
- zoj 3829 Known Notation(贪心)