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…
C. Hacker, pack your bags! time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing…
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…
题意:给定n个优惠券,每张都有一定的优惠区间,然后要选k张,保证k张共同的优惠区间最大. 析:先把所有的优惠券按左端点排序,然后维护一个容量为k的优先队列,每次更新优先队列中的最小值,和当前的右端点, 之间的距离.优先队列只要存储右端点就好. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <…
还记得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…
It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha. So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world.…
题目大意:给你n个旅券,上面有开始时间l,结束时间r,和花费cost,要求选择两张时间不相交的旅券时间长度相加为x,且要求花费最少. 解题思路:看了大佬的才会写!其实和之前Codeforces 776C的写法有点像,遍历l,设以l为起始时间时长为time,看是否存在时长为x-time且与当前时段不相交的时间段,取最小值. 代码: #include<iostream> #include<cstdio> #include<algorithm> #include<vec…
题意 给出一些闭区间(始末+代价),选取两段不重合区间使长度之和恰为x且代价最低 思路 相同持续时间的放在一个vector中,内部再对起始时间排序,从后向前扫获取对应起始时间的最优代价,存在minn中,对时间 i 从前向后扫,在对应的k-i中二分找第一个不重合的区间,其对应的minn加上 i 的cost即为出发时间为 i 时的最优解 代码 #include<bits/stdc++.h> using namespace std; int n, k; struct EVE{ int st,ed,v…
[题目链接]:http://codeforces.com/contest/822/problem/C [题意] 有n个旅行计划, 每个旅行计划以开始日期li,结束日期ri,以及花费金钱costi描述; 让你在这n个旅行计划中选出两个计划; 要求这两个计划的日期没有相交的部分; 且这两个日期的总时间长度恰好为x; 让你求最小花费 [题解] 先把每个计划按照左端点第一优先级,右端点第二优先级升序排序; 然后定义一个dp[x]数组,表示在前i个计划中,时长为x,且右端点的位置< a[i].l的一个旅行…
接上一篇文章; 这里直接把左端点和右端点映射到vector数组上; 映射一个open和close数组; 枚举1..2e5 如果open[i]内有安排; 则用那个安排和dp数组来更新答案; 更新答案完之后,如果有close数组 则把close数组里面的安排用来更新dp数组; #include <bits/stdc++.h> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #def…
C. Hacker, pack your bags!     It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha. So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hac…
Hacker, pack your bags [题目链接]Hacker, pack your bags &题意: 有n条线段(n<=2e5) 每条线段有左端点li,右端点ri,价值cost(1 <= li <= ri <= 2e5, cost <= 1e9) 对于一个给定的x(x <= 2e5),寻找两个不相交的线段,使它们的长度和恰好为x,并且价值和最小 &题解: 只有2个线段,并且他们的和是定值x.但是还有另外一个条件,他们的区间不相交,这个我们可以…
C. Hacker, pack your bags! time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing…
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…
题目链接:http://codeforces.com/contest/822/submission/28248100 题解:多维的可以先降一下维度sort一下可以而且这种区间类型的可以拆一下区间只要加一个标记就知道这是开始区间还是结束区间具体看一下代码. #include <iostream> #include <cstring> #include <algorithm> #include <cstdio> #define inf 1000000000000…
传送门 题意 给出n个区间[l,r]及花费\(cost_i\),找两个区间满足 1.区间和为指定值x 2.花费最小 分析 先用vector记录(l,r,cost)和(r,l,cost),按l排序,再设置一个数组bestcost[i]代表长度为i的最小花费. O(n)扫一遍,如果碰到区间左端点,更新答案:碰到右端点,更新bestcost[len],具体见代码 trick 1.更新答案会爆int 代码 #include <bits/stdc++.h> using namespace std; #d…
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()…
题目大意是给若干线段及其费用,每个线段权值即为其长度.要求找出两个不重合线段,令其权值和等于x且费用最少. 解法: 先分析一下题目,要处理不重合的问题,有重合的线段不能组合,其次这是一个选二问题,当枚举其中一条线段时,另一条合法线段的必要条件“权值”可以直接得出. 对于第一个问题,想到先对线段根据l进行排序,这样每次枚举一个线段的时候,如果在它的l之后有一个合法线段,我们只要标记一下x-LenNow,待枚举到那个合法线段的时候自然就判断出来了.如果在它之前有一个合法线段符合条件,根据刚刚的做法我…
思路: 对于一个区间[l, r],只需枚举所有满足r' < l并且二者duration之和为x的区间[l', r'],寻找其中二者cost之和最小的即可.于是可以开一个数组a[],a[i]表示所有能与i配对的区间(duration为x - i)的最小花费.计算的时候根据区间左端点由小到大依次更新就可以满足区间不重叠的限制,具体参见代码. 实现: #include <iostream> #include <cstdio> #include <vector> usin…
目录 codeforces1080A codeforces 1080B codeforces 1080C codeforces 1080D codeforces 1080E codeforces 1080F codeforces1080A 传送门:https://codeforces.com/contest/1080/problem/A 题意:制造一份邀请函需要2份a物品,5份b物品,8份c物品,一个盒子里面有k份物品(可以为a或b或c)问你制造n份邀请函需要用多少个盒子 题解:直接加起来就行…
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个区间是公共交集最大,就创建一个最小堆的优先队列(只存放区间的右端点):然后按左端点从小到大(先将区间按左端点排序)将区间放入优先队列中.每当优先队列的大…
题目链接:http://codeforces.com/contest/467/problem/B 题目意思:有 m + 1 个 player 和 n 种类型的 soldiers.每个player被赋予一个数xi,然后将xi 看成二进制数,规定第 j 位 如果为1,表示这个 player 有j 这种类型的soldiers.Fedor 是 第 m + 1 个player,问他能跟前面 m 个players 成为 friends 的 人数.成为friends 的条件是被比较的两个人的不同soldier…
All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket. The goods in the supermarket have unique integer ids. Also, for every integer there is a product with id equal to this integer. Fedor has…
题目链接: 题意: 给定n个单词. 以下有m个替换方式.左边的单词能变成右边的单词. 替换随意次后使得最后字母r个数最少,在r最少的情况下单词总长度最短 输出字母r的个数和单词长度. 思路: 我们觉得一个单词有2个參数.则m个替换规则能够当成m个点的有向图. 则某些单词的替换终点会确定,所以反向建图bfs一下. 为了防止某些点被重复更新,所以把每一个点的权值都放到栈里排个序然后bfs. #include<stdio.h> #include<string.h> #include<…
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/转载请注明出处,侵权必究,保留最终解释权! Description All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket. The…
就像title说的,是昨天(2017/9/17)周赛的两道水题…… 题目链接:http://codeforces.com/problemset/problem/14/A time limit per test: 1 second memory limit per test: 64 megabytes A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with n rows and…
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working…
Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the seco…