zoj 3953 三区间重合(贪心)
来源:互联网 发布:java jdbc 编辑:程序博客网 时间:2024/06/05 15:00
Chiaki has n intervals and the i-th of them is [li, ri]. She wants to delete some intervals so that there does not exist three intervals a, b and c such that a intersects with b, b intersects with c and c intersects with a.
Chiaki is interested in the minimum number of intervals which need to be deleted.
Note that interval a intersects with interval b if there exists a real number x such that la ≤ x ≤ ra and lb ≤ x ≤ rb.
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first line contains an integer n (1 ≤ n ≤ 50000) -- the number of intervals.
Each of the following n lines contains two integers li and ri (1 ≤ li < ri ≤ 109) denoting the i-th interval. Note that for every 1 ≤ i < j ≤ n, li ≠ lj or ri ≠ rj.
It is guaranteed that the sum of all n does not exceed 500000.
Output
For each test case, output an integer m denoting the minimum number of deletions. Then in the next line, output m integers in increasing order denoting the index of the intervals to be deleted. If m equals to 0, you should output an empty line in the second line.
Sample Input
1112 54 73 96 111 1210 158 1713 1816 2014 2119 22
Sample Output
43 5 7 10
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<string>#include<map>#include<set>using namespace std;const int N = 50000 + 100;struct P{ int x,y,id; bool operator < (const P& t1)const { return y<t1.y; }}a[N];int b[N];int vis[N];int main(){ int T,n,i,j,end,ans; scanf("%d",&T); while(T--) { memset(vis,0,sizeof(vis)); scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d%d",&a[i].x,&a[i].y); a[i].id=i; } sort(a+1,a+1+n); ans=end=0; P last = a[1]; for(i=2;i<=n;i++) { if(a[i].x<=end) { vis[i]=1; continue; } if(a[i].x<=last.y) end = last.y; last = a[i]; } for(i=1;i<=n;i++) if(vis[i]) b[ans++]=a[i].id; printf("%d\n",ans); sort(b,b+ans); for(i=0;i<ans;i++) printf("%d ",b[i]); printf("\n"); } return 0;}
- zoj 3953 三区间重合(贪心)
- ZOJ 3953 Intervals (贪心/区间交)
- ZOJ 3953 Intervals(区间贪心)
- 区间重合判断(区间覆盖问题)
- 区间重合
- ZOJ 3953 Intervals (贪心)
- 最长重合区间问题
- 2.19 区间重合判断
- 区间重合判断
- 区间重合判断
- 区间重合判断
- 区间重合判断
- 区间重合判断
- 区间重合判断
- 2.19 区间重合判断
- 区间重合判断
- 2.19 区间重合判定
- 区间重合判断
- Array.prototype.filter()
- Neutron采用Openvswitch通用配置【ocata】
- 转发一篇写得不错的关于iptables的文章
- galang 学习之grpc+ protobuf(一)
- HashMap和HashSet的区别
- zoj 3953 三区间重合(贪心)
- Tomcat 浏览器 http
- Centos 7 常用命令
- URAL1998-The old Padawan
- 使用IPtables 实现数据转发
- Ubuntu系统正常使用的搜狗输入法突然无法输出中文
- Scala实现神经网络 ANN , 偏函数式风格
- Unix格式文件转Dos
- Flask使用mysql数据库