2017多校训练第10场-Schedule(贪心+二分)
来源:互联网 发布:关于走心的文案 知乎 编辑:程序博客网 时间:2024/06/10 22:32
一开始的思路就是对的,但是排序搞错了,白wa了5发,大致思路就是按开始时间排序,然后遍历区间,将不相交的区间直接放入set里,相交的话,找结束时间最晚的不相交区间,令其结束时间为当前结束时间,然后重复模拟就好啦
#include<set>#include<map> #include<stack> #include<queue> #include<vector> #include<string> #include<math.h> #include<stdio.h> #include<iostream> #include<string.h> #include<stdlib.h> #include<algorithm> #include<functional> using namespace std;typedef long long ll;#define inf 1000000000 #define mod 1000000007 #define maxn 106000 #define PI 3.1415926 #define lowbit(x) (x&-x) #define eps 1e-9 struct node{ll l, r;bool operator < (node b)const{return r < b.r;}bool operator == (node b)const{return r == b.r;}bool operator > (node b)const{return r > b.r;}}a[maxn], b[maxn];int cnt;bool comp(node a, node b){if (a.l == b.l)return a.r < b.r;return a.l < b.l;}int main(void){int T, n, i, j;scanf("%d", &T);while (T--){cnt = 0;multiset<node>s;multiset<node>::iterator it;scanf("%d", &n);for (i = 1;i <= n;i++)scanf("%lld%lld", &a[i].l, &a[i].r);sort(a + 1, a + n + 1, comp);for (i = 1;i <= n;i++){if (i == 1){b[++cnt] = a[i];s.insert(b[cnt]);}else{node tmp;tmp.l = a[i].r;tmp.r = a[i].l;it = s.upper_bound(tmp);if (it == s.begin()){b[++cnt] = a[i];s.insert(b[cnt]);}else{tmp = *(--it);s.erase(it);tmp.r = a[i].r;s.insert(tmp);}}}ll ans = 0;for (it = s.begin();it != s.end();it++)ans += (*it).r - (*it).l;printf("%d %lld\n", cnt, ans);}return 0;}
阅读全文
1 0
- 2017多校训练第10场-Schedule(贪心+二分)
- 2017多校训练第二场 hdu6047 Maximum Sequence(贪心)
- 2017 多校训练第二场 HDU 6047 Maximum Sequence(贪心+优先队列)
- 2017多校训练赛第四场 HDU 6070(二分答案+线段树+扫描线)
- HDU-2017 多校训练赛10-1010-Schedule
- HDU 6180 && 2017 多校训练:Schedule
- 【多校训练】hdu 6180 Schedule 贪心+set
- (2017多校训练第一场)HDU
- (2017多校训练第一场)HDU
- 2017多校训练第一场
- 2017多校训练第一场
- (2017多校训练第一场)HDU
- (2017多校训练第二场)HDU
- (2017多校训练第二场)HDU
- (2017多校训练第二场)HDU
- (2017多校训练第二场)HDU
- (2017多校训练第三场)HDU
- (2017多校训练第三场)HDU
- Demo(动态数组的添加输出子类继承的排序反转)
- CI AR模型
- CodeIgniter框架源码学习之安全类--Security.php
- python代码简单实现一个词频统计
- Window下安装配置PyOpenGL
- 2017多校训练第10场-Schedule(贪心+二分)
- linux学习笔记(9)
- Chilkat.NET.Components.for.NET.4.0.
- 4.S5PV210中断相关寄存器详解
- 网页JS蜂巢特效
- 关于CSS如果绘制三角形
- CI Model
- UIEdgeInsetsMake设置UIButton的图片、文字的相对位置
- 字符串操作