HDU-2017 多校训练赛10-1010-Schedule
2017-08-28 20:52
302 查看
ACM模版
描述
题解
典型的贪心问题,用 set 维护一下,二分搞搞就行了。代码
#include <iostream> #include <algorithm> #include <cstdio> #include <set> using namespace std; typedef long long int ll; const int MAXN = 1e5 + 5; int n; struct node { int s, e; } a[MAXN]; bool cmp(node a, node b) { return a.s < b.s; } multiset<int> msi; int main() { int T; scanf("%d", &T); while (T--) { scanf("%d", &n); msi.clear(); for (int i = 0; i < n; i++) { scanf("%d%d", &a[i].s, &a[i].e); } sort(a, a + n, cmp); ll ans = 0; for (int i = 0; i < n; i++) { auto it = msi.upper_bound(a[i].s); if (it == msi.begin()) { ans += a[i].e - a[i].s; msi.insert(a[i].e); } else { it--; ans += a[i].e - *it; msi.erase(it); msi.insert(a[i].e); } } printf("%lu %lld\n", msi.size(), ans); } return 0; }
相关文章推荐
- HDU-2017 多校训练赛10-1001-Admiral
- HDU-2017 多校训练赛10-1008-Monkeys
- HDU-2017 多校训练赛10-1011-Two Paths
- HDU-2017 多校训练赛10-补题
- HDU-2017 多校训练赛10-1002-Array Challenge
- HDU 6180 && 2017 多校训练:Schedule
- (2017多校训练第七场)HDU - 6127 Hard challenge 极角排序+尺取法
- 2017 多校训练第二场 HDU 6047 Maximum Sequence
- 2017 Multi-University Training Contest 10 1010 Schedule && HDU 6180 (贪心)
- 【极角排序+双指针线性扫】2017多校训练七 HDU 6127 Hard challenge
- 2017 多校训练第一场 HDU 6035 Colorful Tree
- HDU 6162 && 2017 多校训练:Ch's gift(树链剖分)
- 2017 多校训练第九场 HDU 6168 Numbers 贪心枚举
- 2017 多校训练第六场 HDU 6097 Mindis
- (2017多校训练第二场)HDU - 6052 To my boyfriend 思维题
- 2017 多校训练第一场 HDU 6034 Balala Power!
- HDU 2017 多校联合训练赛7 1010 6129 Just do it 杨辉三角 组合数的奇偶判断
- HDU 4920(杭电多校训练#5 1010 题) Matrix multiplication(不知道该挂个什么帽子。。。)
- 2017 多校训练第二场 HDU 6050 Funny Function
- 2017 多校训练第二场 HDU 6055 Regular polygon