[Codeforces 226E]Noble Knight's Path】的更多相关文章

题目大意:有一棵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,则答…
[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…
题目描述: bz luogu 题解: 主席树维护大力树剖. 一条路径上不允许过的点的个数是当前袭击数-$y$时袭击数, 所以允许经过的点的个数是总数-当前袭击数+$y$时袭击数. 用主席树去维护每个时刻树链袭击数. 这样的话修改的时间复杂度是$O(nlogn)$的. 现在的问题是查询. 注意端点不算路径上的点,那么我们可以让起点和终点距离近一点. 然后有两种情况,起点先向上走/先向下走. 这两个都能用同样的暴跳二分解决. 上代码: #include<cstdio> #include<cs…
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…
题目链接:http://codeforces.com/contest/762/problem/D 多多分析状态:这个很明了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define ls i<<1 #define rs ls | 1 #define mid ((ll+rr)>>1) #define…
这个题目的突破口就是固定最短长度,然后以二进制的形式分层: 最后把需要的曾连起来: #include<cstdio> #include<cstring> #define maxn 105 using namespace std; bool map[maxn][maxn]; void link(int x,int y) { map[x][y]=; map[y][x]=; } void pre() { link(,); link(,); link(,); ; i<; i+=) {…
[链接] 我是链接,点我呀:) [题意] 让你找到(x0,y0)到(x1,y1)的一条最短路 走过的点必须在所给的n个横向路径上 [题解] 因为n条横向路径上的点最多不会超过10的5次方个,所以我们可以把这10的5次方个点全都 和数字1~10^5一一对应. 然后对于这每一个点,分别于相邻的8个点连边. 然后在无向图上做一个广搜就能找到起点到终点的最短路啦 [代码] import java.io.*; import java.util.*; public class Main { static I…
[链接] 我是链接,点我呀:) [题意] n个人矩形m场比赛 每场比赛由编号为li~ri且之前没有被淘汰的人进行. 已知第i场的winner是xi winner会把这一场其他所有的人都淘汰. 问你n个人每个人都是被谁给淘汰的. [题解] 并查集 初始条件f[i] = i,nex[i] = i + 1; 每一轮战斗,让输的人的f[find_father(i)]变成x[i] 但是在执行f[find_father(i)]=x[i]的时候 我们要记录一下ans[find_father(i)] = x[i…
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…