H - Tokens on the Segments(贪心+优先队列)
Output
For each test case output one line containing one integer, indicating the maximum possible number of segments that have at least one token on each of them.
Sample Input
2
3
1 2
1 1
2 3
3
1 2
1 1
2 2
Sample Output
3
2
Hint
For the first sample test case, one can put three tokens separately on (1, 2), (2, 1) and (3, 3).
For the second sample test case, one can put two tokens separately on (1, 2) and (2, 3).
题意:给出许多个区间,每个区间上的每个点都可以被标记,只要每个区间上有一个点被标记,即可记为这个区间被标记(若有区间重叠部分的点被标记,只能代表其中一个区间被标记);求最多可以被标记的区间个数。
思路:对于所有的区间我们进行一个排序,(按左边界小的排序;若左边界同,按右边界小的排序),把这些区间放进一个优先队列,每次都标记左边界,用一个maxx进行记录左边界,如果左边界已经被标记了,就判断区间是否为1,不为1的话就可以把左边界右移一位,然后再次将这个改过的区间加入到优先队列中去。(注意:我一开始用了一个vis判断是否标记,不过忽略了1e9,过大,会产生MLE)
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 +