C. Hongcow Builds A Nation】的更多相关文章

A. Hongcow Builds A Nation 题意: 现在有 n 个点 ,m 条边组成了一个无向图 , 其中有 k 个特殊点, 这些特殊点之间不能连通 ,问可以再多加几条边? 因为$x^2+y^2<=(x+y)^2$,所以找出所有连通块,枚举一个特殊连通块,与其他非特殊连通块合在一起.一个连通块贡献答案:$\frac{Size^2-Size}{2}-已有边$ #include< cstdio > typedef long long ll; template inline void…
题目链接:http://codeforces.com/contest/745/problem/C C. Hongcow Builds A Nation time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Hongcow is ruler of the world. As ruler of the world, he wants t…
C. Hongcow Builds A Nation time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road wit…
http://codeforces.com/problemset/problem/744/A 题意:在一个图里面有n个点m条边,还有k个点是受限制的,即不能从一个受限制的点走到另外一个受限制的点(有路径相连),问在这样的图里面遵守这样的规则可以最多添加几条边. 思路:这种题之前在做强连通的时候很常见,于是就写了tarjan..醒来后发现不用这么复杂,直接用并查集就可以做了. 1.对于每一个连通块,最多可以加上n*(n-1)/2条边. 2.对于受限制的连通块,取出一个点数最多的,和不受限制的块相连…
http://codeforces.com/contest/745/problem/C 把他们并查集后, 其他没有连去government的点,全部放去同一个并查集,然后选择一个节点数最多的government集合,连接过去即可. 至于有多少条边增加,可以暴力判断. #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm&g…
题目链接:http://codeforces.com/contest/745/problem/C 题意:给出n个点m条边,还有k个不能连通的点,问最多能添加几条边. 要知道如果有n个点最多的边是n*(n-1),显然最多的边就是构成一个完全图但是由于有k个点不能连通, 所以先处理一下与k个点链接的几个点,然后再在k个点中选出包含点最多的然后把剩余的点全都与这个 点链接,最后减去m边即可. #include <iostream> #include <cstring> #include…
A. Hongcow Learns the Cyclic Shift time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Bein…
敲完三题挂机一小时.....  也没懂DE什么意思  rank600上了一波分... A. Hongcow Learns the Cyclic Shift 给一个字符串,每次可以把最后一个字符拿到开头  问能形成多少种.. 暴力模拟  set去重... B. Hongcow Solves A Puzzle 判断矩形即可... C. Hongcow Builds A Nation 并查集求最大块  然后把未标记的块放进最大块里  最后的连边数-最初的   为我们添加的最多可能 D. Hongcow…
A. Hongcow Learns the Cyclic Shift time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Bein…
Codeforces Round #385 (Div. 1) <br > A.Hongcow Builds A Nation 贪心. 显然就是凑成一个最大的块即可 那么首先并查集处理已经确定的点 然后把剩下不确定的放到点数最多的一个块中 最后统计边数即可 B.Hongcow's Game 交互题 交互的方法比较特殊. 每次二分一部分区域,然后将可以补充的填上 也就是把矩阵不断的切成四块,然后依次补上 可以把一些子询问合并 因为可能有一半已经有结果了,不会有所影响 举个例子(官方题解): Fir…