题目链接: E. Ants in Leaves time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Tree is a connected graph without cycles. A leaf of a tree is any vertex connected with exactly one other vertex. Yo…
E. Ants in Leaves 题目连接: http://www.codeforces.com/contest/622/problem/E Description Tree is a connected graph without cycles. A leaf of a tree is any vertex connected with exactly one other vertex. You are given a tree with n vertices and a root in t…
题目:点这里 题目的意思跟所谓的是英雄就下100层一个意思……在T秒内能够下到地面,就可以了(还有一个板与板之间不能超过H高). 接触这题目是在昨晚的训练赛,当时拍拍地打了个贪心+dfs,果断跟我想的一模一样,TLE了. 赛后我在宿舍里修改了好几次……均无果.后来,我大胆地假设,估计是最后两组出问题TLE的..于是我就在程序里,指定在最后两组输出yes或者no,就这样奇葩地AC了…… 我实验了三次,总共有2*2种可能……(差点就觉得人品差到不行了) 终于AC了.当然,平时练习真心不要这样子,但是…
题目连接:Codeforces 437C  The Child and Toy 贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子. #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; const int MAX_N = 1000 + 10; int G[MAX_N][MAX_N]; struct…
https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则,假如u在v相邻前面,那么u和v可以交换位置,问你是队列最后一个人的时候你最前可以换到前面哪里 题解 因为相邻才能换,所以最后一个换到前面一定是一步一步向前走,所以不存在还要向后走的情况 设最后一个为u,假设前面有一个能和u换位置的集合,那么需要将这些点尽量往后移动去接u 假设前面有一个不能和u换位置的集合S,…
题目描述 题目简述:树版[k取方格数] 众所周知,桂木桂马是攻略之神,开启攻略之神模式后,他可以同时攻略k部游戏. 今天他得到了一款新游戏<XX半岛>,这款游戏有n个场景(scene),某些场景可以通过不同的选择支到达其他场景.所有场景和选择支构成树状结构:开始游戏时在根节点(共通线),叶子节点为结局.每个场景有一个价值,现在桂马开启攻略之神模式,同时攻略k次该游戏,问他观赏到的场景的价值和最大是多少(同一场景观看多次是不能重复得到价值的) “为什么你还没玩就知道每个场景的价值呢?” “我已经…
/* hdu6060[贪心+dfs] 2017多校3*/ #include <bits/stdc++.h> using namespace std; typedef long long LL; int n, k, u, v, c; struct Edge { LL cost; int to; Edge(, ): cost(C), to(T) {} }; vector<Edge> G[]; ]; LL ans = ; void dfs(int u, int fa) { son[u]+…
题目链接 给一棵有根树, 每个叶子节点上有一只蚂蚁. 在0时刻蚂蚁开始向上爬, 同一时刻, 除了根节点以外, 一个节点上面不能有2个蚂蚁. 问所有的蚂蚁都爬到根节点需要的最短时间. 因为除了根节点, 一个节点上面只能有一个蚂蚁, 所以我们将根节点去掉, 于是就有了一个森林. 时间就是所有子树里面花费时间最多的那棵树的时间. 对于每棵子树, 我们将所有的节点标一个深度, 然后将深度排序. 可以知道 dp[i] = max(dp[i-1]+1, d[i]), d是深度, 这样就可以求得最终答案. #…
K - Cut 'em all! CodeForces - 982C 给一棵树 求最多能切几条边使剩下的子树都有偶数个节点 如果n是奇数 那么奇数=偶数+奇数 不管怎么切 都会有奇数 直接打印-1 贪心 如果子树中的点是偶数 就可以直接切了 最后答案要减一 因为原来的树也是偶数个节点 会被统计进去 #include <cstdio> #include <vector> #include <algorithm> using namespace std; ; int res…
Description Tree is a connected graph without cycles. A leaf of a tree is any vertex connected with exactly one other vertex. You are given a tree with n vertices and a root in the vertex 1. There is an ant in each leaf of the tree. In one second som…