CF226E Noble Knight's Path/bzoj4704 旅行】的更多相关文章

题目描述: bz luogu 题解: 主席树维护大力树剖. 一条路径上不允许过的点的个数是当前袭击数-$y$时袭击数, 所以允许经过的点的个数是总数-当前袭击数+$y$时袭击数. 用主席树去维护每个时刻树链袭击数. 这样的话修改的时间复杂度是$O(nlogn)$的. 现在的问题是查询. 注意端点不算路径上的点,那么我们可以让起点和终点距离近一点. 然后有两种情况,起点先向上走/先向下走. 这两个都能用同样的暴跳二分解决. 上代码: #include<cstdio> #include<cs…
[CF226E]Noble Knight's Path 题目大意: 一棵\(n(n\le10^5)\)个结点的树,初始时所有结点都是白色.\(m(m\le10^5)\)次操作,操作包含以下两种: 将点\(u\)涂黑. 询问从\(u\)到\(v\)的路径上,只考虑\(y\)以后的操作,第\(k\)个白色的结点(不包含\(u\)和\(v\)). 思路: 树链剖分+主席树. 源代码: #include<cstdio> #include<cctype> #include<algori…
题目大意:有一棵n个节点的树,m年.初始每个节点都有.每天有如下操作:1. 给定c,让c没有(c只可能没有一次).2. 给定s,t,k,y,求从第y+1年到现在(即忽略y+1年之前的操作1),s到t的路径上第k个有的节点(不存在输出-1).解题思路:首先树链剖分,然后对每天建主席树.我们把有设为1,没有设为0.则操作1就是单点修改,直接改即可.操作2,我们把整条路径拆成s到lca和lca到t,两边分开考虑.对于s到lca的路径,让s沿着链往上跳,同时进行区间查询.若区间里的点已经大于等于k,则答…
Given a knight in a chessboard (a binary matrix with 0 as empty and 1 as barrier) with a source position, find the shortest path to a destinationposition, return the length of the route. Return -1 if knight can not reached. Notice source and destinat…
The Sorrows of Young Werther J.W. von Goethe Thomas Carlyle and R.D. Boylan Edited by Nathen HaskellDole PREFACE I have carefully collected whatever I have been able to learnof the story of poor Werther, and here present it to you , knowing thatyou w…
1 - 从strStr谈面试技巧与代码风格 必做题: 13.字符串查找 要求:如题 思路:(自写AC)双重循环,内循环读完则成功 还可以用Rabin,KMP算法等 public int strStr(String source, String target) { if (source == null || target == null) { return -1; } char[] sources = source.toCharArray(); char[] targets = target.to…
BFS几类题: 1.图的遍历:a.层级遍历 b.由点及面 c.拓扑排序 2.简单图最短路径: 简单图:1.无向图 2.边权重一致 图的时间复杂度: N个点,M条边,M最大是N^2,时间复杂度O(N+M),最坏是O(N^2); 矩阵是一种特殊图,R行C列矩阵,有R*C个点,R*C*2条边,所以是O(R*C); 69. Binary Tree Level Order Traversal public List<List<Integer>> levelOrder(TreeNode roo…
双向宽度优先搜索 (Bidirectional BFS) 算法适用于如下的场景: 无向图 所有边的长度都为 1 或者长度都一样 同时给出了起点和终点 以上 3 个条件都满足的时候,可以使用双向宽度优先搜索来求出起点和终点的最短距离. 算法描述 双向宽度优先搜索本质上还是BFS,只不过变成了起点向终点和终点向起点同时进行扩展,直至两个方向上出现同一个子节点,搜索结束.我们还是可以利用队列来实现:一个队列保存从起点开始搜索的状态,另一个保存从终点开始的状态,两边如果相交了,那么搜索结束.起点到终点的…
CHAPTER 8 ENGLAND UNDER WILLIAM THE FIRST, THE NORMAN CONQUEROR Upon the ground where the brave Harold fell, William the Norman afterwards founded an abbey, which, under the name of Battle Abbey, was a rich and splendid place through many a troubled…
[BZOJ4704]旅行 Description 在Berland,有n个城堡.每个城堡恰好属于一个领主.不同的城堡属于不同的领主.在所有领主中有一个是国王,其他的每个领主都直接隶属于另一位领主,并且间接隶属于国王.一位领主可以拥有任意数量的下属.这些城堡被一些双向的道路连接.两个城堡是连接的当且仅当他们的主人中一位直接隶属于另一位.每一年,在Berland会发生以下两件事中的一件:1.野蛮人攻击了城堡c.这是城堡c第一次也会是最后一次被攻击,因为野蛮人从来不攻击同一座城堡超过一次.2.一个骑士…
A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 41936   Accepted: 14269 Description Background The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey ar…
2. 旅行计划 ★☆   输入文件:djs.in   输出文件:djs.out   简单对比时间限制:3 s   内存限制:128 MB 过暑假了,阿杜准备出行旅游,他已经查到了某些城市的两两之间的距离及可行路线(可行路线有方向),如下图所示.请你编程计算从阿杜所住城市到其它城市的最短路径以帮助阿杜制定旅行计划. [输入格式] 输入由若干行组成,第一行有三个整数,$n(1≤n≤100).m(1≤m≤n^2).v(1≤m≤n)$:城市数,$m$城市间道路数,$v$是阿杜所住城市.第$2$至$m+1…
题目链接:http://poj.org/problem?id=2488 A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 36695   Accepted: 12462 Description Background The knight is getting bored of seeing the same black and white squares again and again…
A Knight's Journey Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 35564 Accepted: 12119 Description Background The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey around…
A Knight's Journey Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total Submission(s) : 51   Accepted Submission(s) : 17 Problem Description Background The knight is getting bored of seeing the same black and white…
Description Background The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey around the world. Whenever a knight moves, it is two squares in one direction and one square perpendicular…
A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 31702   Accepted: 10813 Description Background  The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey …
Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 25950   Accepted: 8853 Description Background The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey around the world. When…
A Knight's Journey Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 34633Accepted: 11815 Description BackgroundThe knight is getting bored of seeing the same black and white squares again and again and has decided to make a journeyaround the…
A Knight’s Journey Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 34085 Accepted: 11621 Description Background The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey around…
  A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 24840   Accepted: 8412 Description Background   The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey…
2015-06-05 问题简述: 有一个 p*q 的棋盘,一个骑士(就是中国象棋里的马)想要走完所有的格子,棋盘横向是 A...Z(其中A开始 p 个),纵向是 1...q. 原题链接:http://acm.tju.edu.cn/toj/showp1702.html 解题思路: DFS:深搜把所有情况都考虑一遍,当骑士走出棋盘或走到原来走过的格子时,旅行失败了:当骑士能一直走下去直到走过的格子数等于 p*q 时,旅行成功. 提交过程中一直有一个问题使这个代码一直WA,最后才发现是 p.q输入反了…
深搜,从一点向各处搜找到全部能走的地方. Problem Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on…
Knight Moves option=com_onlinejudge&Itemid=8&category=11&page=show_problem&problem=380" target="_blank" style="text-decoration:none">From:UVA, 439 Time Limit: 3000 MS A friend of you is doing research on the Tra…
A Knight's Journey Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total Submission(s) : 66   Accepted Submission(s) : 27 Problem Description Background The knight is getting bored of seeing the same black and white…
A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28697   Accepted: 9822 Description Background  The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey  a…
Background The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey around the world. Whenever a knight moves, it is two squares in one direction and one square perpendicular to this. Th…
http://poj.org/problem?id=2488 Description Background The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey around the world. Whenever a knight moves, it is two squares in one directi…
Description BackgroundThe knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey around the world. Whenever a knight moves, it is two squares in one direction and one square perpendicular…
A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 31195   Accepted: 10668 Description Background The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey ar…