[USACO11DEC]牧草种植Grass Planting】的更多相关文章

题目描述 Farmer John has N barren pastures (2 <= N <= 100,000) connected by N-1 bidirectional roads, such that there is exactly one path between any two pastures. Bessie, a cow who loves her grazing time, often complains about how there is no grass on t…
题目描述 Farmer John has N barren pastures (2 <= N <= 100,000) connected by N-1 bidirectional roads, such that there is exactly one path between any two pastures. Bessie, a cow who loves her grazing time, often complains about how there is no grass on t…
题目描述 Farmer John has N barren pastures (2 <= N <= 100,000) connected by N-1 bidirectional roads, such that there is exactly one path between any two pastures. Bessie, a cow who loves her grazing time, often complains about how there is no grass on t…
题目描述 Farmer John has N barren pastures (2 <= N <= 100,000) connected by N-1 bidirectional roads, such that there is exactly one path between any two pastures. Bessie, a cow who loves her grazing time, often complains about how there is no grass on t…
题解:仍然是无脑树剖,要注意一下边权,然而这种没有初始边权的题目其实和点权也没什么区别了 代码如下: #include<cstdio> #include<vector> #include<cstring> #include<iostream> #include<algorithm> #define lson root<<1 #define rson root<<1|1 using namespace std; struct…
图很丑.明显的树链剖分,需要的操作只有区间修改和区间查询.不过这里是边权,我们怎么把它转成点权呢?对于E(u,v),我们选其深度大的节点,把边权扔给它.因为这是树,所以每个点只有一个父亲,所以每个边权都可以唯一地.不重复地转移到点上去(除了根节点).但是做区间操作时就要注意一下,区间两边端点的LCA的权值是不可以用的. 这么简单的模板题就直接放代码了: #include<iostream> #include<cstring> #include<cstdio> #defi…
模拟题,可以用树链剖分+线段树维护. 但是学了一个厉害的..树状数组的区间修改与区间查询.. 分割线里面的是转载的: -------------------------------------------------------------------------------- [ 3 ]  上面都不是重点……重点是树状数组的区间修改+区间查询 这个很好玩 其实也挺简单 首先依旧是引入delta数组 delta[i]表示区间 [i, n] 的共同增量 于是修改区间 [l, r] 时修改 delt…
表示看不太清. 概括题意 树上维护区间修改与区间和查询. 很明显树剖裸题,切掉,细节处错误T了好久 TAT 代码 #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #define int long long #define R register #define ls o<<1 #define rs o<<1|1 #define N 50000…
思路: 首先,这道题的翻译是有问题的(起码现在是),查询的时候应该是查询某一条路径的权值,而不是某条边(坑死我了). 与平常树链剖分题目不同的是,这道题目维护的是边权,而不是点权,那怎么办呢?好像有点棘手诶,这是一种非常经典的题型,我们可以发现,一个点最多只有一个父亲!!!那,我们显然就可以用这个点的点权去代替它与它父亲之间的边权!!!然后这道题不就成了树链剖分水题了嘛?刚开始边权都是\(0\),那我们就根据题目给的边建边权为\(0\)的边. \(nonono\),还有一个坑点就是在路径查询和修…
洛谷 P3038 [USACO11DEC]牧草种植Grass Planting 洛谷传送门 JDOJ 2282: USACO 2011 Dec Gold 3.Grass Planting JDOJ传送门 Description Problem 3: Grass Planting [Travis Hance, 2011] Farmer John has N barren pastures (2 <= N <= 100,000) connected by N-1 bidirectional roa…
题目传送门 牧草种植 题目描述 Farmer John has N barren pastures (2 <= N <= 100,000) connected by N-1 bidirectional roads, such that there is exactly one path between any two pastures. Bessie, a cow who loves her grazing time, often complains about how there is no…
Grass Planting 题意 给出一棵树,树有边权.每次给出节点 (u, v) ,有两种操作:1. 把 u 到 v 路径上所有边的权值加 1.2. 查询 u 到 v 的权值之和. 分析 如果这些值不是在树上,而是在区间上,那么凭借线段树.树状数组可以很轻松的解决,但是在树上则不能直接操作. 树链剖分就是将树上的节点映射到区间上,从而实现区间操作. 学习树链剖分前需要掌握的知识点:线段树.LCA. 参考blog 认真读完这篇 blog ,跟着算法流程走一遍差不多就懂了. code #incl…
题目描述 Farmer John has N barren pastures (2 <= N <= 100,000) connected by N-1 bidirectional roads, such that there is exactly one path between any two pastures. Bessie, a cow who loves her grazing time, often complains about how there is no grass on t…
题目大意: 有一棵结点个数为n的树,有m个操作,可以将一段路径上每条边的权值+1或询问某一个边的权值. 思路: 树链剖分+线段树. 轻重链划分本身比较简单,主要需要思考如何用线段树维护每条链. 当x,y不在同一条链上时,先处理深度大的链,对于每一个链,建立一棵动态开点的线段树,用一个数组len顺序记录每一条边在链中的编号,然后维护len[x]+1到len[top[x]]这一区间的权值即可. 处理轻边时,可以直接用一个数组保存它的权值. 因为轻重边肯定是交替的,因此每次循环都可以先维护一个重边,再…
Description Farmer John has N barren pastures connected by N-1 bidirectional roads, such that there is exactly one path between any two pastures. Bessie, a cow who loves her grazing time, often complains about how there is no grass on the roads betwe…
54  种草约翰有 N 个牧场,编号为 1 到 N.它们之间有 N − 1 条道路,每条道路连接两个牧场.通过这些道路,所有牧场都是连通的.刚开始的时候,所有道路都是光秃秃的,没有青草.约翰会在一些道路上批量种草.每次开始种草的时候,约翰会选择一个牧场作为起点,一个牧场作为终点,找到从起点到终点的最短路径,在这条路径上所有的道路上分别种下一棵新的青草.贝西在监督约翰的工作,她迫不及待地想知道每条道路上已经有多少青草了.约翰的工作总是被贝西打断,他不胜其烦,所以请你来帮忙回答贝西的问题.约翰的工作…
大致题意: 维护一棵树,支持两种操作: P x y x到y路径上的每条边的值+1:Q x y 询问x到y路径上所有边的值的和.Input第一行两个正整数,N,M表示点数和操作数:接下来N-1行每行两个数表示一条边:接下来M行表示M个操作,每行形如P x y或Q x y.2≤N≤100,000,1≤M≤100,000.OutputM行,对应相应询问的答案.Sample Input4 61 42 43 4P 2 3P 1 3Q 3 4P 1 4Q 2 4Q 1 4Sample Output212 /…
小结:昨天由于做的题目比较少,所以就和今天写在一块了,昨天学习了差分约束和树上差分,当然树上差分是用线段树来维护的,今天重点整理了博客\(233\),然后做了几个题. 一. 完成的题目: 洛谷P3275,洛谷P4878,洛谷P2294,洛谷P3258,洛谷P3038,洛谷P1262,洛谷P5159,洛谷P4113 二. 1.当日完成题目数:8道. 2. 未完成6个题目的原因: 3. 复习的知识点:树链剖分,线段树,差分约束,tarjan,数论,树状数组 4.不会题目:洛谷P5160 三: 1.…
Root    3719 - Grass is Green Time limit: 3.000 seconds This year exactly n <tex2html_verbatim_mark>people bought land in Squareville_including you. When someone buys land, then the first thing they do is to plant grass on the land; everyone wants t…
1.luogu P4315 月下"毛景树" 题目链接 前言: 这大概是本蒟蒻A掉的题里面码量最大的一道题了.我自认为码风比较紧凑,但还是写了175行. 从下午2点多调到晚上8点.中间小错不断.最后还是借助了郭神的AC代码.. %%%stO郭神Orz%%% 还是我代码能力不够.以后要多写一些这样的题练练手. 解析: 题目相当裸.树链剖分+线段树维护区间最大值. 需要注意的点大致如下: 1.边权化点权 2.线段树需要实现的功能:区间加,区间赋值,区间查询最大值. 看起来貌似有手就行其实对于…
随时可能弃坑. 因为不知道最近要刷啥所以就决定刷下usaco. 优先级排在学习新算法和打比赛之后. 仅有一句话题解.难一点的可能有代码. 优先级是Gold>Silver.Platinum刷不动...(可能有一两道?) 2015 Feb Gold BZOJ3939. [Usaco2015 Feb]Cow Hopscotch 这题洛谷数据过水,\(O(n^4)\)的dp跑的飞快...所以建议在bzoj写. 但是还是要考虑一下4次方的dp的...其实就是强行枚举转移点,我们可以试着维护前缀和,那么只要…
BZOJ 4777 被权限了. 这道题的做法看上去不难,但是感觉自己yy不出来. 首先是两个结论: 1.答案一定是连接着两个异色点的一条边. 2.答案一定在最小生成树上. 感觉看到了之后都比较显然,自己想……算了吧……想不出来的…… 那么我们可以对每一个点开一个以颜色为下标的线段树,对这棵树存一存它儿子的颜色到它的距离,然后在叶子结点维护一个$multiset$,把所有颜色相同的点都丢进去,然后维护一个最小值$lst_x = min(query(1, 1, k, 1, col_x - 1), q…
题目描述 In an effort to better manage the grazing patterns of his cows, Farmer John has installed one-way cow paths all over his farm. The farm consists of N fields, conveniently numbered 1..N, with each one-way cow path connecting a pair of fields. For…
P3119 [USACO15JAN]草鉴定Grass Cownoisseur 题目描述 约翰有\(n\)块草场,编号1到\(n\),这些草场由若干条单行道相连.奶牛贝西是美味牧草的鉴赏家,她想到达尽可能多的草场去品尝牧草. 贝西总是从1号草场出发,最后回到1号草场.她想经过尽可能多的草场,贝西在通一个草场只吃一次草,所以一个草场可以经过多次.因为草场是单行道连接,这给贝西的品鉴工作带来了很大的不便,贝西想偷偷逆向行走一次,但最多只能有一次逆行.问,贝西最多能吃到多少个草场的牧草. 输入输出格式…
草鉴定Grass Cownoisseur 题目链接 约翰有n块草场,编号1到n,这些草场由若干条单行道相连.奶牛贝西是美味牧草的鉴赏家,她想到达尽可能多的草场去品尝牧草. 贝西总是从1号草场出发,最后回到1号草场.她想经过尽可能多的草场,贝西在通一个草场只吃一次草,所以一个草场可以经过多次.因为草场是单行道连接,这给贝西的品鉴工作带来了很大的不便,贝西想偷偷逆向行走一次,但最多只能有一次逆行.问,贝西最多能吃到多少个草场的牧草. 如果没有逆行操作和回到1的限制,我们很容易想到一种方法: Tarj…
题目描述 In an effort to better manage the grazing patterns of his cows, Farmer John has installed one-way cow paths all over his farm. The farm consists of N fields, conveniently numbered 1..N, with each one-way cow path connecting a pair of fields. For…
P3119 [USACO15JAN]草鉴定Grass Cownoisseur 题目描述 In an effort to better manage the grazing patterns of his cows, Farmer John has installed one-way cow paths all over his farm. The farm consists of N fields, conveniently numbered 1..N, with each one-way co…
[USACO15JAN]草鉴定Grass Cownoisseur 题目描述 In an effort to better manage the grazing patterns of his cows, Farmer John has installed one-way cow paths all over his farm. The farm consists of N fields, conveniently numbered 1..N, with each one-way cow path…
P3119 [USACO15JAN]草鉴定Grass Cownoisseur 题目描述 In an effort to better manage the grazing patterns of his cows, Farmer John has installed one-way cow paths all over his farm. The farm consists of N fields, conveniently numbered 1..N, with each one-way co…
P3119 [USACO15JAN]Grass Cownoisseur G tarjan缩点+分层图上跑 spfa最长路 约翰有 \(n\) 块草场,编号 \(1\) 到 \(n\),这些草场由若干条单行道相连.奶牛贝西是美味牧草的鉴赏家,她想到达尽可能多的草场去品尝牧草. 贝西总是从 \(1\) 号草场出发,最后回到 \(1\) 号草场.她想经过尽可能多的草场,贝西在通一个草场只吃一次草,所以一个草场可以经过多次. 因为草场是单行道连接,这给贝西的品鉴工作带来了很大的不便,贝西想偷偷逆向行走一…