传送门 题意 给出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…
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…
Codeforces Round #422 (Div. 2) Table of Contents Codeforces Round #422 (Div. 2)Problem A. I'm bored with lifeProblem B.Crossword solvingProblem C. Hacker, pack your bags! Problem A. I'm bored with life A. I'm bored with life Holidays have finished. T…
[题目链接]: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…
E. Liar     The first semester ended. You know, after the end of the first semester the holidays begin. On holidays Noora decided to return to Vičkopolis. As a modest souvenir for Leha, she brought a sausage of length m from Pavlopolis. Everyone know…
B. Crossword solving     Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It's well known that it is a very interesting occupation though it can be very difficult f…
A. I'm bored with life     Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for…
[题目链接]:http://codeforces.com/contest/822/problem/D [题意] 有n个人参加选美比赛; 要求把这n个人分成若干个相同大小的组; 每个组内的人数是相同的; 然后每个组内的人,两两比较; 每个组得出最美的人; 然后每个组中最美的人再重复上述步骤; 直到只剩一个人; 问你如何选定每个阶段的分组; 使得比较的次数最少; [题解] 只考虑一轮的情况; 设x是分组后每个组的人数; 然后一共有n个人; 则这一轮比较的次数就为 nx∗x∗(x−1)2 ->n∗(x…
[题目链接]:http://codeforces.com/contest/822/problem/B [题意] 让你用s去匹配t,问你最少需要修改s中的多少个字符; 才能在t中匹配到s; [题解] O(n2)的暴力搞就好; [Number Of WA] 1 [反思] 一开始判断的时候脑抽了; 写成只有s[1]==t[1]的时候才枚举; hack点是: 很多人两重for循环,没有给j层循环加限制; 直接两层循环1..n和1..m [完整代码] #include <bits/stdc++.h> u…