P2986 [USACO10MAR]伟大的奶牛聚集Great Cow Gat… 题目描述 Bessie is planning the annual Great Cow Gathering for cows all across the country and, of course, she would like to choose the most convenient location for the gathering to take place. Each cow lives in on…
首先考虑怎么check一个点是否能被最后一个删除. 可以这么建图,以这个点建有根树,边全部向上指,再加上剩下的有向边. 很明显,这里的一条边的定义就变成了只有删去这个点,才可以删去它指向的点. 因此,只需要建n次图暴力判断是否有环即可. 这样做是n^2的. 考虑加入一条边后,会产生什么影响. 发现这条边会导致一些点答案直接被钦定为零(这些点满足以它们为根一定会存在环) 设边为u---->v 具体分析一下,这些点是所有以v为根建有根树后,u子树内的所有点. 这个可以通过类似换根的分类讨论的方法来找…
首先可以思考一下每次能删去的点有什么性质. 不难发现,每次能删去的点都是入度恰好为 \(1\) 的那些点(包括 \(a_i \rightarrow b_i\) 的有向边). 换句话说,每次能删去的点既要是树上的叶子节点,并且不会被任意一条有向边 \(a_i \rightarrow b_i\) 指向.那么再来思考一下每个点能否走后离开. 因为 \(i\) 号点只能最后离开,那么我们将 \(i\) 看作这课树的根(因为每次只能走叶子).你会发现如果 \(i\) 不能最后走当前仅当会存在一条路径(走有…
P1472 奶牛家谱 Cow Pedigrees 102通过 193提交 题目提供者该用户不存在 标签USACO 难度普及+/提高 提交  讨论  题解 最新讨论 暂时没有讨论 题目描述 农民约翰准备购买一群新奶牛. 在这个新的奶牛群中, 每一个母亲奶牛都生两个小奶牛.这些奶牛间的关系可以用二叉树来表示.这些二叉树总共有N个节点(3 <= N < 200).这些二叉树有如下性质: 每一个节点的度是0或2.度是这个节点的孩子的数目. 树的高度等于K(1 < K < 100).高度是从…
题目戳 题目描述 Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the gang are practicing jumping over hurdles. They are getting tired, though, so they want to be able to use as little energy as possible to jump over th…
双栈排序 思路: 二分图染+模拟: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 1005 #define maxm 2000005 int n,head[maxn],E[maxm],V[maxm],cnt,col[maxn]; int minn[maxn],ai[maxn],sta1[maxn],sta2[maxn],top1,top2; bool if_[maxn][maxn]; inline void in(…
题目描述 Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the gang are practicing jumping over hurdles. They are getting tired, though, so they want to be able to use as little energy as possible to jump over the hu…
问题描述 For their physical fitness program, N (2 ≤ N ≤ 1,000,000) cows have decided to run a relay race using the T (2 ≤ T ≤ 100) cow trails throughout the pasture. Each trail connects two different intersections (1 ≤ I1i ≤ 1,000; 1 ≤ I2i ≤ 1,000), each…
你以为它是一个期望dp,其实它是一个凸包哒! 设平衡木长度为\(L\),把向右走平衡木那个式子写一下: \[dp[i]=\frac{dp[i+1]+dp[i-1]}{2}\] 然后会发现这是一个等差数列,显然有\(dp[0]=0,dp[L]=1\) 所以\(dp_{i\rightarrow L}=\frac{i}{L}\) 向左走同理:\(dp_{i\rightarrow 1}=\frac{L-i}{L}\) 令停止点为直接从这个点跳下去能得到期望报酬最高的点,设点\(i\)左右两端的停止点分别…
这题就是让你求字典序第k小的最短乱序子序列 转换一下,其实就是字典序第k大的最长上升子序列 就统计一下以i结尾的最长上升子序列\(f[i]\),长度为i的上升子序列的开头组成的集合\(v[i]\),转移时贪心转移就行了 然而并不是很懂为什么计算\(f[i]\)时要倒着计算-- 代码: #include <bits/stdc++.h> #define N 100005 #define ll long long #define inf 1e18 using namespace std; vecto…