题意:给定n个优惠券,每张都有一定的优惠区间,然后要选k张,保证k张共同的优惠区间最大. 析:先把所有的优惠券按左端点排序,然后维护一个容量为k的优先队列,每次更新优先队列中的最小值,和当前的右端点, 之间的距离.优先队列只要存储右端点就好. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <…
D. Fedor and coupons time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket. The goo…
D. Fedor and coupons time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket. The goo…
还记得lyf说过k=2的方法,但是推广到k是其他的话有点麻烦.现在这里采取另外一种方法. 先将所有线段按照L进行排序,然后优先队列保存R的值,然后每次用最小的R值,和当前的L来维护答案即可.同时,如果Q的size()比k大,那么就弹出最小的R. 具体见代码: #include <stdio.h> #include <algorithm> #include <string.h> #include <set> #include <vector> #i…
D. Fedor and coupons time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket. The goo…
2个多小时,弱智了..(连A都做不对,就不要做D了(迷)) #include<bits/stdc++.h> #define lowbit(x) x&(-x) #define LL long long #define N 100005 #define M 1000005 #define mod 2147483648LL #define inf 0x7ffffffff using namespace std; inline int ra() { ,f=; char ch=getchar()…
题目描述: C. Producing Snow time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of i…
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard output All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket. The goods in the supermarket hav…
http://codeforces.com/contest/754/problem/D 题意: 给定几组区间,找k组区间,使得它们的公共交集最大. 思路: 在k组区间中,它们的公共交集=k组区间中右端点最小值-k组区间中左端点最大值.如果我们要区间大,那我们应该尽量让左端点小,右端点大. 先对区间按照左端点排序,然后用优先队列处理. 将区间按照左端点从小到大的顺序一一进队列,只需要进右端点即可,如果此时队列内已有k个数,则队首就是这k组区间的最小右端点,而因为左端点是从小到大的顺序进队列的,所以…
题意:题目简化了就是要给你n个区间,然后让你选出k个区间  使得这k个区间有公共交集:问这个公共交集最大能是多少,并且输出所选的k个区间.如果有多组答案,则输出任意一种.   这题是用优先队列来处理区间问题的,感觉挺典型的所以记录下来.   首先,要知道 选取的k个区间的最大交集=区间右端点中的最小值-区间左端点中的最大值.那么,要求得这这么k个区间是公共交集最大,就创建一个最小堆的优先队列(只存放区间的右端点):然后按左端点从小到大(先将区间按左端点排序)将区间放入优先队列中.每当优先队列的大…