Codeforces 746G New Roads (构造)】的更多相关文章

                                                                        G. New Roads                                                                    time limit per test: 2 seconds                                                             memory…
Description There are n cities in Berland, each of them has a unique id - an integer from 1 to n, the capital is the one with id 1. Now there is a serious problem in Berland with roads - there are no roads. That is why there was a decision to build n…
\(>Codeforces\space835 F. Roads in the Kingdom<\) 题目大意 : 给你一棵 \(n\) 个点构成的树基环树,你需要删掉一条环边,使其变成一颗树,并最小化删掉环边后的树的直径. \(n \leq 2 \times 10^5\) 树的边权 $ \leq 10^9 $ 解题思路 : 考虑最终树的直径可能由两部分组成,答案是其中的最大值 第一种就是外向树内的直径的最大值,这个只需要随便\(dp\)一下即可,这里不过多讨论 第二种情况树的直径经过原来的环,…
大意:构造n结点树, 高度$i$的结点有$a_i$个, 且叶子有k个. 先确定主链, 然后贪心放其余节点. #include <iostream> #include <algorithm> #include <cstdio> #include <math.h> #include <set> #include <map> #include <queue> #include <string> #include &l…
                                                                                                  G. New Roads                                                                                                time limit per test 2 seconds               …
题目链接:G. New Roads 题意:给出n个结点,t层深度,每层有a[i]个结点,总共有k个叶子结点,构造一棵树. 分析: 考虑一颗树,如果满足每层深度上有a[i]结点,最多能有多少叶子结点 那么答案很简单,就是对(a[i]-1)求和再加1(每一层的结点都集中在上一层的一个结点上)   同理,我们考虑最少能有多少叶子结点,就是把上一个的答案再减去min(a[i]-1, a[i-1]-1)的求和,就是每一层的结点都尽可能的分散在上一层的结点 根据这个,那么如果要求有k个叶子节点,k在最大值与…
[题目链接]:http://codeforces.com/problemset/problem/746/G [题意] 给你3个数字n,t,k; 分别表示一棵树有n个点; 这棵树的深度t,以及叶子节点的个数k; 给你树的每层节点个数; 让你画出这么一棵树; 输出它的n-1条边; [题解] 先构造出一棵树的主链; 即t层,每层的第一个节点都连在一起; 然后,把第二层的节点都和头结点都连在一起; 这时有t个点,它们已经不可能是叶子节点了,还有tot=n-k-t,需要把这n-k-t都变成不是叶子节点(非…
题目链接:点击打开链接 题意: 给定n个点 m条边的无向图 须要在图里添加p条边 使得图最后连通分量数为q 问是否可行,不可行输出NO 可行输出YES,并输出加入的p条边. set走起.. #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> #include<vector> #include<set> using namespace s…
ZS the Coder and Chris the Baboon has explored Udayland for quite some time. They realize that it consists of n towns numbered from1 to n. There are n directed roads in the Udayland. i-th of them goes from town i to some other town ai (ai ≠ i). ZS th…
Codeforces 题面传送门 & 洛谷题面传送门 一道不算困难的构造,花了一节英语课把它搞出来了,题解简单写写吧( 考虑从大往小加数,显然第三个条件可以被翻译为,每次加入一个元素,如果它所在的行/列存在元素,那么它必须为这一行/列所在的元素相邻,因此我们考虑这样构造,当我们加入一个数 \(v\) 时,分以下几种情况考虑: 如果 \(v\) 在原矩阵中既是行的最大值,也是列的最大值,那我们新开一行一列并将这个元素塞进去.即我们动态维护一个 \(R,C\) 表示目前有 \(R\) 行 \(C\)…