[atAGC007E]Shik and Travel】的更多相关文章

二分枚举答案,判定答案是否合法 贪心:每一个叶子只能经过一遍,因此叶子的顺序一定是一个dfs序,即走完一棵子树中的所有叶子才会到子树外 根据这个贪心可以dp,设$f[k][l][r]$表示仅考虑$k$的子树,$l$和$r$为第一个和最后一个叶子到根的距离,时间复杂度大约有$o(n^{4或5})$,无法通过 考虑优化,将所有$f[k][l][r]=1$的$(l,r)$记录下来,若存在$l'\le l$且$r'\le r$,$(l,r)$一定没有意义,这可以用一个单调栈来维护,那么同一个$l/r$所…
Shik and Travel Time Limit: 50 Sec  Memory Limit: 512 MB Description 给定一棵n个点的树,保证一个点出度为2/0. 遍历一遍,要求每条边被经过两次,第一次从根出发,最后一次到根结束,在叶子节点之间移动. 移动一次的费用为路径上的边权之和,第一次和最后一次免费,移动的最大费用 最小可以是多少. Input 第一行一个n,表示点数. 之后两个数x, y,若在第 i 行,表示 i+1 -> x 有一条权值为 y 的边. Output…
AGC007E Shik and Travel 题目大意:\(n\) 个点的二叉树,每个点要么两个儿子,要么没有儿子,每条边有边权. 你从 \(1\) 号节点出发,走到一个叶子节点.然后每一天,你可以从当前点走到另一个叶子.最后回到 \(1\) 号节点,要求到过所有叶子并且每条边经过恰好两次.求一种遍历顺序,使得每相邻两叶子间的边权和的最大值最小. 题解 考虑二分最大值,看是否可行.这个点是一种类似等号转限制的做法. 因此我们只需考虑能否在不经过权值和大于 \(k\) 的叶子间的路径即可.这个怎…
题目链接 AtCoder:https://agc007.contest.atcoder.jp/tasks/agc007_e 洛谷:https://www.luogu.org/problemnew/show/AT2172 Solution 首先由于每条边只能经过两次,所以每次到了\(x\)点就会遍历完\(x\)子树再出来. 考虑二分答案,设当前二分的答案为\(mid\). 设二元组\((a,b)_x\)表示\(x\)子树下第一次走代价为\(a\)最后一次为\(b\),且中间的过程都\(\leqsl…
题目传送门:https://agc007.contest.atcoder.jp/tasks/agc007_e 题目翻译 现在有一个二叉树,除了叶子每个结点都有两个儿子.这个二叉树一共有\(m\)个叶子,你需要从\(1\)号点出发,旅行\(m+1\)天后回到\(1\)号结点,其中前\(m\)天每天需要在叶子节点结束,并且每个叶子结点只允许被经过一次,每条边只允许被经过两次,边有边权,旅行的费用即为两点之间简单路径上权值之和,然后问你费用最大的一天最小可以是多少.第一天和最后一天免费. 题解 嗯,这…
题目描述: luogu 题解: 二分+暴力$vector$+$dfs$. 记录下所有可能的子树内合法方案,双指针+归并合并. 代码: #include<vector> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; ; template<typename T> inline void read(T&a…
题目 给定一棵n节点的 以1为根的 满二叉树 (每个非叶子节点恰好有两个儿子)n−1 条边. 第ii条边连接 i+1号点 和 ai, 经过代价为vi设这棵树有m个叶子节点定义一次合法的旅行为:(1) 旅行m+1天, 旅行从11号点出发, 最后回到11号点(2) 第 1 ..m天, 每天 从上一天的结束点出发, 前往一个叶子节点, 然后结束这一天 (记第0天的结束点为1) 第 m+1 天, 从上一天的结束点出发, 前往1号点(3) 旅行过程中, 每条边恰好经过两次定义一天的花费为 : 起点到终点的…
题目链接 https://atcoder.jp/contests/agc007/tasks/agc007_e 题解 首先有个很朴素的想法是,二分答案\(mid\)后使用可行性DP, 设\(dp[u][x][y]\)表示\(u\)子树内是否可以找到一条路径,在经过第一个叶子前路程是\(x\), 经过最后一个叶子前路程是\(y\). 这个DP显然做了很多无用功,比如我们发现完全可以只记录true的状态\((x,y)\),进一步发现如果合法状态\((x,y)\)存在另一合法状态\((x',y')\)满…
AtCoder Grand Contest 007 A - Shik and Stone 翻译 见洛谷 题解 傻逼玩意 #include<cstdio> int n,m,tot;char ch[10]; int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;++i) { scanf("%s",ch+1); for(int j=1;j<=m;++j) tot+=ch[j]=='#'…
一句话题解 QwQ主要是因为这篇文章写的有点长……有时候要找某一个题可能不是很好找,所以写了这个东西. 具体的题意.题解和代码可以再往下翻._(:з」∠)_ AGC 001 C:枚举中点/中边. D:构造. E:根据组合数意义转为$DP$. F:拓扑排序,线段树优化连边. AGC 002 C:水题,看是否有a[i]+a[i+1]>=k. D:并查集上倍增,二分答案. E:博弈(坑) F:模型转化然后$DP$. AGC 003 C:一个数到自己应到位置距离为奇数的个数/2. D:数学,质因数分解,…
AGC007 A Shik and Stone 我是沙比这都能蛙一发 https://agc007.contest.atcoder.jp/submissions/7946110 B Construct Sequences 造两个等差数列\(20000,40000,\ldots,20000n\)和反过来作为基础\(A,B\),然后在上面减一下就好了. https://agc007.contest.atcoder.jp/submissions/7946428 C Pushing Balls 真tmd…
构造题都是神仙题 /kk ARC066C Addition and Subtraction Hard 首先要发现两个性质: 加号右边不会有括号:显然,有括号也可以被删去,答案不变. \(op_i\)和\(A_{i+1}\)之间只会有一个括号:有多个括号的话只保留最外边那个,答案不变. 然后就可以定义状态:\(dp_{i,j}\)表示前\(i\)个数,还有\(j\)个未闭合的左括号,得到的最大答案. 由于只有减号右边有括号,所以只要知道左边有几个未闭合的左括号,就可以知道自己的贡献是\(1\)还是…
AGC007 A - Shik and Stone 如果i + j走过的格子只有一个,那么就是可以走到 #include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define…
颓!颓!颓!(bushi 前传: 贪心/构造/DP 杂题选做 贪心/构造/DP 杂题选做Ⅱ 51. CF758E Broken Tree 讲个笑话,这道题是 11.3 模拟赛的 T2,模拟赛里那道题的名字叫猛张(orz ztr),而我刚好在 11.4 把这题 A 了.乍一看好像也没啥问题,不过模拟赛时间是 2020.11.3,而我 AC 这道题的时间是 2021.11.4((( 首先看到这样的题我们肯定会想到贪心,具体来说我们 DFS 一遍整棵树,DFS 到一个节点 \(x\) 时,我们考虑用最…
CF1039D You Are Given a Tree 容易发现,当 \(k\) 不断增大时,答案不断减小,且 \(k\) 的答案不超过 \(\lfloor\frac {n}{k}\rfloor\) ,因此不同的答案个数是 \(\sqrt n\) 级别的,可以用一种类似整体二分的方式求解. 对于一个 \(k\) ,从叶子节点贪心向上匹配即可得到答案. 点击查看代码 #include<bits/stdc++.h> using namespace std; int n; int ver[2000…
Travel The country frog lives in has nn towns which are conveniently numbered by 1,2,…,n. Among n(n−1) / 2 pairs of towns, m of them are connected by bidirectional highway, which needs aa minutes to travel. The other pairs are connected by railway, w…
1576: [Usaco2009 Jan]安全路经Travel Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1044  Solved: 363[Submit][Status][Discuss] Description Input * 第一行: 两个空格分开的数, N和M * 第2..M+1行: 三个空格分开的数a_i, b_i,和t_i Output * 第1..N-1行: 第i行包含一个数:从牛棚_1到牛棚_i+1并且避免从牛棚1到牛棚i+1最…
目录 . Linux inode简介 . Fast Directory Travel Method 1. Linux inode简介 0x1: 磁盘分割原理 字节 -> 扇区(sector)(每个扇区存储512字节) -> 块(block)(最常见的是4KB,即8个连续的sector组成一个block) . 磁盘的最小存储单位是"扇区" . 文件存储的最小单位是"块" 0x2: Linux EX2 filesystem 当一个partition(分区)被…
Problem Description Jack likes to travel around the world, but he doesn’t like to wait. Now, he is traveling in the Undirected Kingdom. There are n cities and m bidirectional roads connecting the cities. Jack hates waiting too long on the bus, but he…
I. Travel Time Limit: 3000ms Memory Limit: 65536KB The country frog lives in has n towns which are conveniently numbered by 1,2,-,n. Among n(n−1)/2 pairs of towns, m of them are connected by bidirectional highway, which needs a minutes to travel. The…
1286. Starship Travel Time limit: 1.0 secondMemory limit: 64 MB It is well known that a starship equipped with class B hyperengine is able to travel from any planet to any other planet. But your starship got severe damage in the last travel and now i…
DescriptionAfter SzuHope take part in the 36th ACMICPC Asia Chendu Reginal Contest. Then go to QingChengShan for fun. QCS has many spot as the picture following, each spot has its unique value for SzuHope, they will get the value just once if and onl…
Time Limit: 1500/1000 MS (Java/Others)  Memory Limit: 131072/131072 K (Java/Others) Problem Description Jack likes to travel around the world, but he doesn’t like to wait. Now, he is traveling in the Undirected Kingdom. There are n cities and m bidir…
A. Flea travel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/problem/A Description A flea is sitting at one of the n hassocks, arranged in a circle, at the moment. After minute number k the flea jumps through k - 1hass…
Travel Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5441 Description Jack likes to travel around the world, but he doesn’t like to wait. Now, he is traveling in the Undirected Kingdom. There are n cities and m…
1576: [Usaco2009 Jan]安全路经Travel Time Limit: 10 Sec  Memory Limit: 64 MB Submit: 665  Solved: 227[Submit][Status] Description Input * 第一行: 两个空格分开的数, N和M * 第2..M+1行: 三个空格分开的数a_i, b_i,和t_i Output * 第1..N-1行: 第i行包含一个数:从牛棚_1到牛棚_i+1并且避免从牛棚1到牛棚i+1最短路经上最后一条牛…
Safe Travel Time Limit: 3000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Main Gremlins have infested the farm. These nasty, ugly fairy-like creatures thwart the cows as each one walks from the barn (conveniently locat…
The Best Travel Design Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1359   Accepted: 340 Description Dou Nai is an excellent ACM programmer, and he felt so tired recently that he wants to release himself from the hard work. He plans a…
Travel Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2404    Accepted Submission(s): 842 Problem Description Jack likes to travel around the world, but he doesn’t like to wait. Now, he is tr…
Travel Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2055    Accepted Submission(s): 709 Problem Description Jack likes to travel around the world, but he doesn’t like to wait. Now, he is tr…