Hrbust 2319 Number Game(贪心)】的更多相关文章

题目链接  Hrbust 2319 首先把二元组排序,$ai$大的排前面,$ai$相同的$bi$大的排前面. 这样的话就满足了Kim的取数顺序,即选每次$ai$最大的. 考虑得坏一些,在$ai$相同的时候每次选$bi$最大的. 我们从第$2$个位置开始考虑,默认选排名为偶数的,并且一个个把取到的$bi$放进优先队列(小根堆) 当位置标号为奇数并且堆顶元素小于当前的$bi$的时候把堆顶元素弹出来并且把这个$bi$放进去. 其意义为放弃前面标号为偶数点$bi$小的,抓这个编号为奇数并且$bi$大的.…
题目描述: time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Dima worked all day and wrote down on a long paper strip his favorite number n consisting of l digits. Unfortunately, the strip turned…
原文链接https://www.cnblogs.com/zhouzhendong/p/9074226.html 题目传送门 - Codeforces 980E 题意 $\rm Codeforces$ 真是个令人伤心的地方. 伤心的 $zzd$ 给你一个有 $n$ 个节点的树,编号为 $i$ 的节点权值为 $2^i$. 让你砍掉其中 $k$ 个节点,使得剩余的所有节点都连通,并最大化剩余节点的权值和.输出方案. $n\leq 10^6$ 题解 伤心的 $zzd$ 再一次来到了令人伤心的 $\rm…
仔细看题想想就是个贪心题,两个sort就可以解决了 #include<stdio.h> #include<string.h> #include<math.h> #include<time.h> #include<iostream> #include<ctype.h> #include<map> #include<set> #include<string> #include<vector>…
首先将每个括号序列转化为三元组(ai,bi,ci),其中ai为左括号-右括号数量,bi为前缀最小左括号-右括号数,ci为序列长度.问题变为在满足Σai=0,bi+Σaj>=0 (j<i)的情况下,最大化Σci. 考虑在确定了选哪些序列的情况下如何排列能够尽量满足条件.显然应该把ai>0的放在前面,<0的放在后面.对于ai>=0,考虑按bi降序排列.因为假设这样排列后第一个不合法的位置是x,要让该位置合法显然应该将x后面的某个三元组i和前面的交换,但该三元组的bi<bx,…
题目传送门 传送点I 传送点II 传送点III 题目大意 给定一颗有$n$个点的树,$i$号点的权值是$2^{i}$要求删去$k$个点,使得剩下的点仍然连通,并且总权值和最大,问删去的所有点的编号. 其实这道题和虚树没有太大的关系,我只是提一下而已. 因为点的权值很特殊,所以相当于要求剩下序列(从大到小)的字典序最大. 然后过程就比较显然了.从大到小枚举点,判断能否保留它(计算加入它后,新的树的点数有没有超过限制).保留它是指和已经被保留的点连通. 这个相当于使得一些关键点连通,然后求出总点数.…
https://codeforc.es/contest/1189/problem/B 优先考虑最大的元素怎么构造.拿两个次大的围着他就很好,但是其他的怎么安排呢?就直接降序排列就可以了. a数组还开错了. #include<bits/stdc++.h> using namespace std; typedef long long ll; int n; int a[100005]; int main() { #ifdef Yinku freopen("Yinku.in", &…
A. Easy Number Game 贪心将第$i$小的和第$2m-i+1$小的配对即可. #include<cstdio> #include<algorithm> using namespace std; const int N=100010; int n,m,i,Case,a[N];long long ans; int main(){ scanf("%d",&Case); while(Case--){ scanf("%d%d",…
[题目] There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it's horizontal, y-coordinates don't matter and hence the x-coordinates…
Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change. You h…