题意:建一颗以\(1\)为根结点的树,询问\(q\)次,每次询问一个结点,问该结点的第\(k\)个子结点,如果不存在则输出\(-1\). 题解:该题数据范围较大,需要采用dfs预处理的方法,我们从结点\(1\)开始向下找,\(ans\)数组记录的是,第\(x\)次查找时的结点,\(path\)表示某个结点所需的查找次数,\(siz\)数组表示某个结点的子结点个数.之后每次询问时,判断一下情况是否成立,如果成立,先找出该结点所对应的查找次数(\(path[u]\)),向下找第\(k\)个子结点即可…
题意问,这个点的然后求子树的第i个节点. 这道题是个非常明显的DFS序: 我们只需要记录DFS的入DFS的时间,以及出DFS的时间,也就是DFS序, 然后判断第i个子树是否在这个节点的时间段之间. 最后用一个映射,把相应DFS序对应的节点编号写入.即可 #include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> #include<vector> using…
题目链接:Codeforces Round #367 (Div. 2) C. Hard problem 题意: 给你一些字符串,字符串可以倒置,如果要倒置,就会消耗vi的能量,问你花最少的能量将这些字符串排成字典序 题解: 当时1点过头太晕了,看错题了,然后感觉全世界都会,就我不会,- -!结果就是一个简单的DP, 设dp[i][0]表示第i个字符串不反转的情况,dp[i][1]表示第i个字符串反转的情况 状态转移方程看代码 #include<bits/stdc++.h> #define F(…
Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have three piles of candies: red, green and blue candies: the first pile…
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help. Vasiliy is given n strings consisting of lowercase Engl…
[比赛链接] 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);…
题目连接:http://codeforces.com/contest/688/problem/C 题意:给你一些边,问你能否构成一个二分图 题解:二分图:二分图又称作二部图,是图论中的一种特殊模型. 设G=(V,E)是一个无向图,如果顶点V可分割为两个互不相交的子集(A,B),并且图中的每条边(i,j)所关联的两个顶点i和j分别属于这两个不同的顶点集(i in A,j in B),则称图G为一个二分图. 直接上一个DFS就搞定了 #include<cstdio> #include<set…
C. NP-Hard Problem 题目连接: http://www.codeforces.com/contest/688/problem/C Description Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting. Suppose the graph G is given. Subs…
http://codeforces.com/contest/1006/problem/A Mishka got an integer array aa of length nn as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's A…
链接: https://codeforces.com/contest/1263/problem/A 题意: You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are r candies in it, the second pile contains only green candies and there are g ca…