Codeforces822 C. Hacker, pack your bags!】的更多相关文章

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…
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!     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…
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…
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.…
题目大意是给若干线段及其费用,每个线段权值即为其长度.要求找出两个不重合线段,令其权值和等于x且费用最少. 解法: 先分析一下题目,要处理不重合的问题,有重合的线段不能组合,其次这是一个选二问题,当枚举其中一条线段时,另一条合法线段的必要条件“权值”可以直接得出. 对于第一个问题,想到先对线段根据l进行排序,这样每次枚举一个线段的时候,如果在它的l之后有一个合法线段,我们只要标记一下x-LenNow,待枚举到那个合法线段的时候自然就判断出来了.如果在它之前有一个合法线段符合条件,根据刚刚的做法我…
题目大意:给你n个旅券,上面有开始时间l,结束时间r,和花费cost,要求选择两张时间不相交的旅券时间长度相加为x,且要求花费最少. 解题思路:看了大佬的才会写!其实和之前Codeforces 776C的写法有点像,遍历l,设以l为起始时间时长为time,看是否存在时长为x-time且与当前时段不相交的时间段,取最小值. 代码: #include<iostream> #include<cstdio> #include<algorithm> #include<vec…
传送门 题意 给出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…
思路: 对于一个区间[l, r],只需枚举所有满足r' < l并且二者duration之和为x的区间[l', r'],寻找其中二者cost之和最小的即可.于是可以开一个数组a[],a[i]表示所有能与i配对的区间(duration为x - i)的最小花费.计算的时候根据区间左端点由小到大依次更新就可以满足区间不重叠的限制,具体参见代码. 实现: #include <iostream> #include <cstdio> #include <vector> usin…