CodeForces 1141F2 贪心 离散化】的更多相关文章

正解: 贪心+离散化+逆序对 解题报告: 链接在这儿呢quq 这题其实主要难在想方法吧我觉得?学长提点了下说用贪心之后就大概明白了,感觉没有很难 但是离散化这里还是挺有趣的,因为并不是能很熟练地掌握离散化(昂其实理解得还不错……主要实现太少TT) 所以在这里放一下 #include<bits/stdc++.h> using namespace std; struct str { long long hei,id; }mat1[],mat2[]; ],g[],p[],ans; long long…
[Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r.每次操作的代价为改变数的个数.问:要让操作后序列里不同数的个数\(k\)满足$n \lceil \log _2 k\rceil \leq 8I $,操作的最小代价 分析 首先把a离散化,这样[l,r]都在\(10^5\)的级别.枚举l,发现r显然有单调性.操作后不同数的个数随r的增大而减小(考虑极端情况l=…
https://codeforces.com/contest/1141/problem/F2 题意 一个大小为n的数组a[],问最多有多少个不相交的区间和相等 题解 离散化用值来做,贪心选择较前的区间 代码 #include<bits/stdc++.h> #define M 5000005 #define ll long long #define pb push_back using namespace std; struct N{int l,r;N(int l=0,int r=0):l(l)…
要点 一开始dp然后码力太辣鸡并且算法带假于是调了很久一交还WA在28-- 吐槽完毕.后来想拿栈优化dp时发现其实完全不需要dp,贪心选取即可,当前的不兼容就干脆不要它了,结果不会变差.然后想要什么就预处理什么即可. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <vector> #include <unorder…
http://codeforces.com/problemset/problem/893/D 题意 Recenlty Luba有一张信用卡可用,一开始金额为0,每天早上可以去充任意数量的钱.到了晚上,银行会对信用卡进行一次操作,操作有三种操作. 1.如果a[i]>0,银行会给卡充入a[i]元. 2.如果a[i]<0 银行从卡中扣除a[i]元. 3.如果a[i]=0 银行会查询卡里的金额. 有两条规则,如果违背信用卡就会被冻结. 1.信用卡里的金额不能大于d. 2.当银行查询卡里的金额时,金额不…
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebo…
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of n nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exactly k of t…
链接 大意:给定$nk$块木板, 要制作$n$个$k$块板的桶, 要求任意两桶容积差不超过$l$, 每个桶的容积为最短木板长, 输出$n$个桶的最大容积和 假设最短板长$m$, 显然最后桶的体积都在$[m,m+l]$范围内, 就是说需保证每个桶都至少有一块板在$[m,m+l]$范围. 考虑贪心逐步调整, 假设$m+l$足够多的话, 可以先尽量连续得选最短的边做桶, 最后将$m+l$分给剩余桶即为最大容积. 如果不够多的话, 就要选出$m+l-1$分给剩余桶, 还不够就选择$m+l-2$, 直到所…
题目链接:http://codeforces.com/gym/101149/problem/G 题目大意:给你n对数字,为(a[i], b[i]),给你m对数字,为(w[i], c[i]).给n对数字找配对,这个配对必须是m中的,而且m中的每个只能和n中的配对一次. 配对条件,w[i]>=a[j], c[i]>=b[j]即可配对. 输出n个数字,每个数字在m个数字当中的配对. 思路:假定n对数字的是x,m对数字的是y 离散化以后sort一下x和y,这样我们就得到了第一维是排序好了的. 然后我们…
题目链接:http://codeforces.com/problemset/problem/93/B B. End of Exams time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Students love to celebrate their holidays. Especially if the holiday is th…