CodeForces1006E- Military Problem】的更多相关文章

J - Military Problem CodeForces - 1006E 就是一道dfs序的问题 给定一个树, 然后有q次询问. 每次给出u,k, 求以u为根的子树经过深搜的第k个儿子,如果一个节点有多个儿子,按照儿子从小到大的顺序,依次访问,不存在则输出-1. 预处理记录一下每个节点的出入时间 最后每次query直接判断就好了 #include <cstdio> #include <algorithm> #include <vector> using names…
http://codeforces.com/contest/1006/problem/E 题意: 就是给出n,m,共n个点[1,n],m次询问.第二行给出n-1个数a[i],2<=i<=n:a[i]表示i的父亲节点是a[i]. 按照题目给构建一棵树,每次询问,找到从一个结点u开始DFS到第k个的节点编号是多少,这样的点不存在时输出-1. 思路: 如果对每个查询都DFS一次,必超时 所以必须预处理 这里用vector存边,用son[i]表示编号为i的点自身+孩子结点的总个数 ,用rk[i]表示遍…
题意问,这个点的然后求子树的第i个节点. 这道题是个非常明显的DFS序: 我们只需要记录DFS的入DFS的时间,以及出DFS的时间,也就是DFS序, 然后判断第i个子树是否在这个节点的时间段之间. 最后用一个映射,把相应DFS序对应的节点编号写入.即可 #include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> #include<vector> using…
题意: 就是有一颗树  然后每次询问 父结点 的 第k个结点是不是他的子嗣...是的话就输出这个子嗣..不是 就输出-1 解析: 突然想到后缀数组的sa 和 x的用法..就是我们可以用一个id标记当前结点的等级 用idx标记等级ans是哪一个结点..然后用en标记结点u的子嗣的结束结点 然后每次判断一下就可以了 #include <iostream> #include <cstdio> #include <sstream> #include <cstring>…
题意:建一颗以\(1\)为根结点的树,询问\(q\)次,每次询问一个结点,问该结点的第\(k\)个子结点,如果不存在则输出\(-1\). 题解:该题数据范围较大,需要采用dfs预处理的方法,我们从结点\(1\)开始向下找,\(ans\)数组记录的是,第\(x\)次查找时的结点,\(path\)表示某个结点所需的查找次数,\(siz\)数组表示某个结点的子结点个数.之后每次询问时,判断一下情况是否成立,如果成立,先找出该结点所对应的查找次数(\(path[u]\)),向下找第\(k\)个子结点即可…
E. Military Problem time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output In this problem you will have to help Berland army with organizing their command delivery system. There are nn officers…
A - Lake Counting POJ - 2386 最最最最最基础的dfs 挂这道题为了提高AC率(糖水不等式 B - Paint it really, really dark gray CodeForces - 717E dfs 待会写题解 C - New Year Transportation CodeForces - 500A 简单的模拟 D - Binary Tree Traversals HDU - 1710 给树的先序中序输出后序 贴下代码 #include <algorith…
                                                                           . A. Adjacent Replacements 执行1e9次命令,输出的最后数组的样子 一个奇数执行两次命令 会变回原来的数字 一个偶数只会执行一次命令 变成比自身小1的数 #include<bits/stdc++.h> #define int long long #define MAX(a,b,c) max(a,max(b,c)) #de…
[比赛链接] https://codeforces.com/contest/1006 [题解] Problem A. Adjacent Replacements        [算法] 将序列中的所有偶数替换为奇数即可 时间复杂度 : O(N) [代码] #include<bits/stdc++.h> using namespace std; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y);…
牛客专题之DFS序 简介 dfs序: 每个节点在dfs深度优先遍历中的进出栈的时间序列,也就是tarjan算法中的dfn数组. 画个图理解一下: 这棵树的dfs序:1 3 2 4 2 5 6 7 6 5 1. 那么这个序列有什么用呢? 通过观察,两个相同数字之间就是以它为根的子树, 也就是说,通过dfs序我们可以得到,这个节点第一次进入栈的时间戳\(l_i\)和第一次出栈的时间戳\(r_i\).之后我们就可以通过\(l_i\)和\(r_i\)操纵这棵树了. 具体看题: 模板 Military P…
From Wikipedia, the free encyclopedia       Animation showing how the date would reset, represented as a signed 32-bit integer (at 03:14:08 UTC on 19 January 2038). The Year 2038 problem is an issue for computing and data storage situations in which…
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id=1199 Problem B: 大小关系 Time Limit: 2 Sec  Memory Limit: 128 MBSubmit: 148  Solved: 31[Submit][Status][Web Board] Description 当我们知道一组大小关系之后,可判断所有关系是否都能成立…
Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem. 解决的办法是把对应的Class改成静态类.…
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 688C uDebug Description   Input   Output   Sample Input   Sample Output   Hint…
I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codeschool yearly subscribed, but I have lost the track long time. I get more weight than expected. I like more and more my MacBook Pro I maybe go to the UST…
    Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and made an amazing discovery: there are only 16 types of programming contest problems! Furthermore, the top several comprise almost 80% of the problems s…
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前几项为 : 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845, 35357670- 令h(0)=1,h(1)=1,catalan数满足递推式:      h(n)= h(0…
2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit][Status][Discuss] Description 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. Input 第一行一个整数n,接下来n行每行五个整数,分别表示a.b.c.d.k Outp…
You are given two jugs with capacities x and y litres. There is an infinite amount of water supply available. You need to determine whether it is possible to measure exactly z litres using these two jugs. If z liters of water is measurable, you must…
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and height of all the buildings as shown on a cityscape photo (Figure A), write a pr…
$s = curl_init(); curl_setopt($s, CURLOPT_POST, true); curl_setopt($s, CURLOPT_POSTFIELDS, $queryStr); curl_setopt($s, CURLOPT_URL, $url); curl_setopt($s, CURLOPT_TIMEOUT, 1000); curl_setopt($s, CURLOPT_RETURNTRANSFER, 1); $body = curl_exec($s); if($…
3489: A simple rmq problem Time Limit: 40 Sec  Memory Limit: 600 MBSubmit: 1594  Solved: 520[Submit][Status][Discuss] Description 因为是OJ上的题,就简单点好了.给出一个长度为n的序列,给出M个询问:在[l,r]之间找到一个在这个区间里只出现过一次的数,并且要求找的这个数尽可能大.如果找不到这样的数,则直接输出0.我会采取一些措施强制在线. Input 第一行为两个整…
http://codeforces.com/problemset/problem/442/B (题目链接) 题意 n个人,每个人有p[i]的概率出一道题.问如何选择其中s个人使得这些人正好只出1道题的概率最大. Solution 很显然的概率dp,过了样例即可AC..话说我为什么要刷B题→_→ 代码 // codeforces442B #include<algorithm> #include<iostream> #include<cstdlib> #include<…
A^B Problem 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Give you two numbers a and b,how to know the a^b's the last digit number.It looks so easy,but everybody is too lazy to slove this problem,so they remit to you who is wise.   输入 There are mutiple te…
A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each node has a boolean (0 or 1) labeled on it. Initially, all the labels are 0. We define this kind of operation: given a subtree, negate all its labels. An…
K - Yet Another Multiple Problem Time Limit:20000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4474 Appoint description:  System Crawler  (2014-10-16) Description There are tons of problems about integer mul…
Recently ,I got confused When I use  git to push one of my project. The problem is below: And I Found the solutions  below maybe helpful to someone who meet the problem: Dealing with non-fast-forward errors Sometimes, Git can't make your change to a…
Cisco的VPN客户端最近报"AnyConnect was not able to establish connection to the specified secure gateway." 导致连不上公司VPN了. 有人说取消共享 Problem: AnyConnect was not able to establish a connection to the specified secure gateway. Please try connecting again. Envir…
题目链接:http://poj.org/problem?id=3311 题意:一个人到一些地方送披萨,要求找到一条路径能够遍历每一个城市后返回出发点,并且路径距离最短.最后输出最短距离即可.注意:每一个地方可重复访问多次. 经典的状压dp,因为每次送外卖不超过10个地方,可以压缩. 由于题中明确说了两个城市间的直接可达路径(即不经过其它城市结点)不一定是最短路径,所以需要借助floyd首先求出任意两个城市间的最短距离. 然后,在此基础上来求出遍历各个城市后回到出发点的最短路径的距离,即求解TSP…
  To save a visual to an image file need to use RenderTargetBitmap, detail is reference to Save and read images in WPF. But sometimes you will find the output image was shifted or left blank. This is because that RenderTargetBitmap render the visual…