ZOJ - 3953 Intervals 【贪心】】的更多相关文章

题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3953 题意 给出N个区间,求去掉某些区间,使得剩下的区间中,任何的三个区间都不两两相交. 思路 将所有区间 以左端点为键值从小到大排序 然后三个三个一组 进行判断 如果 这三个中有两两相交的 那么就删去右端点最大的 因为这个区间对答案的贡献最小 然后三个区间当中没有两两相交的,那么下一次进来的区间就替换掉右端点最小的. AC代码 #include <cstdio…
线段树,排序. 按照$R$从小到大排序之后逐个检查,如果$L$,$R$最大值不超过$2$,那么就把这个区间放进去,区间$+1$,否则不能放进去. #include<bits/stdc++.h> using namespace std; int T,n,sz; ]; ]; ],m[]; int P; bool cmp(X a,X b) { return a.R<b.R; } int get(int x) { ,rr=sz,res; while(ll<=rr) { ; ; else i…
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 aintersects with b, b intersects with c and c intersects with a. Chiaki is interested in the…
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5572 Intervals Time Limit: 1 Second      Memory Limit: 65536 KB      Special Judge Chiaki has n intervals and the i-th of them is [li, ri]. She wants to delete some intervals so that there do…
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5572 题意:给出n个线段,问最少删除几个线段可以使得任意一个点不会被三个以上的线段覆盖. 思路:首先离散化坐标. 然后想着按右端点从小到大排序后直接O(n)扫的贪心,但是后面发现错误了. 应该按左端点从小到大排序,然后用一个优先队列(按右端点从大到小排序). 开始扫坐标,当有与该坐标相同的点的左端点就进队,用ed[]记录右端点的位置. 用cnt记录当前这个点有多少个区间覆盖,…
题目链接: POJ:http://poj.org/problem?id=1201 HDU:http://acm.hdu.edu.cn/showproblem.php? pid=1384 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=508 Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn.…
递增子序列的最小组数.可以直接贪心,扫一遍 #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; struct stick{ int h,w; }Sticks[]; bool cmp(stick a,stick b) { return (a.h<b.h)||(a.h==b.h&&(a.w<b.w)…
(- ̄▽ ̄)-* //求一个集合,这个集合与任意一个区间的交集,需至少有两个数字 //贪心过程:按n个区间的最右值从小到大对区间进行排列, //集合首先取第一个区间的最右两个数字, //到第二个区间,判断集合里的数有没有在区间里 //没有的话,就从第二个区间的最右开始往左取(cnt=0取最后两个数,cnt=1取最后一个数) #include<iostream> #include<cstdio> #include<cstring> #include<algorith…
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 th…
Intervals Time Limit: 10 Seconds      Memory Limit: 32768 KB You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a program that: > reads the number of intervals, their endpoints and integers c1, ..., cn from the stand…