Codeforces 题面传送门 & 洛谷题面传送门 考虑以 \(1\) 为根,记 \(siz_i\) 为 \(i\) 子树的大小,那么可以通过询问 \(S=\{2,3,\cdots,n\},T=\{1\}\) 以及每个 \(u\) 得出 \(siz_u\) 的值. 考虑将所有点按 \(siz\) 从小到大排序并维护一个集合 \(st\) 表示目前还没有找到父亲的点的集合,那么我们枚举到一个点 \(x\) 时就在 \(st\) 中二分找到所有父亲为 \(x\) 的点并将它们从 \(st\) 中删…
题目链接 \(Description\) 有一棵\(n\)个点的树.你需要在\(11111\)次询问内确定出这棵树的形态.每次询问你给定两个非空且不相交的点集\(S,T\)和一个点\(u\),交互库会告诉你满足\(x\in S,y\in T\),且\(x\to y\)经过了\(u\)的点对\((x,y)\)的数量. \(n\leq500\). \(Solution\) 不妨假设以\(1\)为根.首先如果想知道\(y\)是否在\(x\)的子树内,询问\(S=\{1\},T=\{y\},u=x\)就…
ACM思维题训练集合 There is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number i and col…
原题:http://codeforces.com/contest/675/problem/C 让我们用数组a保存每个银行的余额,因为所有余额的和加起来一定为0,所以我们能把整个数组a划分为几个区间,每个区间的和都为0.对于每个区间来说,设该区间长度为l,则让该区间都为0的操作数为l-1,例如:1 .1 .-3 .1的操作数为3,也就是说,若把a分成k个区间,则a所需要的总的操作数为n-k. 所以现在我们的目标就是把数组a划分为尽可能多的部分,这个时候我们可以用一个map,统计前缀和的个数,因为对…
题目链接:https://codeforces.com/contest/1090/problem/D Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these…
Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with nn nodes. In the beginning, 00 is written on all edges. In one operation, you can choose any 22 dist…
D. Minimum Triangulation time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a regular polygon with nn vertices labeled from 11 to nn in counter-clockwise order. The triangulatio…
A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!!\n") #define pb push_back #define inf 1e9 //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vect…
题目地址: 选题为入门的Codeforce div2/div1的C题和D题. 题解: A:CF思维联系–CodeForces -214C (拓扑排序+思维+贪心) B:CF–思维练习-- CodeForces - 215C - Crosses(思维题) C:CF–思维练习–CodeForces - 216C - Hiring Staff (思维+模拟) D:CF思维联系–CodeForces-217C C. Formurosa(这题鸽了) E:CF思维联系–CodeForces - 218C E…
Codeforces 1129 E.Legendary Tree 解题思路: 这题好厉害,我来复读一下官方题解,顺便补充几句. 首先,可以通过询问 \(n-1​\) 次 \((S=\{1\},T=\{2\dots n\},i),i\in[2,n]​\) ,来得到以 \(1​\) 为根树的所有节点的子树大小. 然后考虑从子树大小最小的节点开始,为每一个节点找它们的儿子,由于每个节点儿子的子树大小,一定小于这个节点的子树大小,所以可以按照子树大小从小到大排序,每个节点的儿子就一定在其前面. 假设已经…