Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Input The first line contains a single integer nn (2≤n≤150000) — the number of kittens. Each of the following n−1lines contains integers xi and yi (1≤xi,…
F. Asya And Kittens Asya loves animals very much. Recently, she purchased nn kittens, enumerated them from 11 and nn and then put them into the cage. The cage consists of one row of nn cells, enumerated with integers from 11 to nn from left to right.…
F. Asya And Kittens time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Asya loves animals very much. Recently, she purchased nn kittens, enumerated them from 11 and nn and then put them into…
reference :https://www.cnblogs.com/ZERO-/p/10426473.html…
Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Description Input Output Print exactly one integer — the beauty of the product of the strings. Sample Input 3aba Sample Output 3 题解:这个题的思维难度其实不大,需要维护什么东西很容易想到,或…
Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input Output The first line of output should contain "Yes", if it's possible to do a correct evaluation for all the dishes, or "No" otherwis…
Codeforces Round #582 (Div. 3)-G. Path Queries-并查集 [Problem Description] 给你一棵树,求有多少条简单路径\((u,v)\),满足\(u\)到\(v\)这条路径上的最大值不超过\(k\).\(q\)次查询. [Solution] 并查集 将所有边按权值从小到大排序,查询值\(k_i\)也从小到大排序.对于每次查询的值\(k_i\),将边权小于等于\(k_i\)的边通过并查集合并在一起.对于合并后的联通块,每个联通块对答案的贡献…
题面: 传送门 题目描述: Asya把N只(从1-N编号)放到笼子里面,笼子是由一行N个隔间组成.两个相邻的隔间有一个隔板. Asya每天观察到有一对想一起玩,然后就会把相邻的隔间中的隔板取出来,使两个相邻的隔间合并为一个隔间. 过了N-1天后,所有隔板将被取出,然后所有的隔间合并成一个隔间. 现在Asya记得每天想一起玩的的编号,要求:在最开始(笼子的所有隔板未取出前)隔间的位置.如果有多种可能,输出其中一种. 题目分析: 这道题是一道典型的并查集,我们还是先分析一下样例. 首先,1和4想一起…
#451 Div2 F 题意 给出一个由数字组成的字符串,要求添加一个加号和等号,满足数字无前导 0 且等式成立. 分析 对于这种只有数字的字符串,可以快速计算某一区间的字符串变成数字后并取模的值,首先从右到左,将字符串转化为数字并取模,那么 \(h[i]\) 表示字符串 \(S[i...len]\) 转化成数字后并取模的值,如果要求区间 \([i, j]\) 所表示的数字是多少,首先求出 \(h[i] - h[j + 1]\),后面的 0 可以除掉,求一下逆元即可. 然后枚举一下,比一下就行了…
#452 Div2 F 题意 给出一个字符串, m 次操作,每次删除区间 \([l,r]\) 之间的字符 \(c\) ,输出最后得到的字符串. 分析 通过树状数组和二分,我们可以把给定的区间对应到在起始字符串上的区间. 然后暴力去删字符即可(因为最多只会删掉等同于字符串长度的字符个数),总共只有 62 种字符,set 维护下位置. code #include<bits/stdc++.h> using namespace std; typedef long long ll; const int…