codeforces 755C. PolandBall and Forest】的更多相关文章

C. PolandBall and Forest time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graph…
题意:给定每一点离他最远的点,问是这个森林里有多少棵树. 析:并查集,最后统计不同根结点的数目即可. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include &…
题意:给定n个数,Ai的下标为1~n.对于每一个i,Ai与i在同一个树上,且是与i最远的点中id最小的点(这个条件变相的说明i与Ai连通).求森林中树的个数. 分析:若i与Ai连通,则在同一个树上,因此连通块的个数就是树的个数.并查集即可. #pragma comment(linker, "/STACK:102400000, 102400000") #include<cstdio> #include<cstring> #include<cstdlib>…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 e…
http://codeforces.com/problemset/problem/755/C 题意:该图是类似于树,给出n个点,接下来p[i]表示在树上离 i 距离最远的 id 是p[i],如果距离相等则p[i]是 id 较小的点. 思路:一开始没什么想法,画几分钟图发现不到什么东西,后来想着 i 和 p[i] 有关系,那么就代表 i 和 p[i] 是属于同一棵树,那么不就是并查集了嘛.抱着试一试的心态搞了一下居然过了. #include <cstdio> #include <cstri…
PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vertex is a valid tree. There is exactly one relative living…
题目链接:http://codeforces.com/problemset/problem/501/C 题目意思:有 n 个点,编号为 0 - n-1.给出 n 个点的度数(即有多少个点跟它有边相连)以及跟它相连的点的编号的异或结果.最后需要输出整幅图的所有边的情况. 这道题确实是一道很好的题目!!!!它说拓扑排序的变形,需要队列的运用,还有就是异或计算的性质!!!(非一般厉害) 由于是无向无环的简单图,换言之就是一棵树啦^_^.那么它就肯定有叶子结点,叶子节点的度数为1,此时它相邻点的异或结果…
D. PolandBall and Polygon time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. P…
PolandBall and Gifts 转换成置换群后, 对于最大值我们很好处理. 对于最小值, 只跟若干个圈能否刚好组能 k 有关. 最直观的想法就是bitset优化背包, 直接搞肯定T掉. 我们能再发掘一些性质, 就是本质不能的圈的大小最多有sqrt(n)个, 因为1 + 2 + 3 ... + n = (n + 1) * n / 2 所以对于每个不同的数二进制优化一下就可以过啦. 感觉这种题就很有意思.. #include<bits/stdc++.h> #define LL long…
Minimal Diameter Forest 首先我们找出每个连通块中的特殊点, 特殊点的定义是到各种个连通块中距离的最大值最小的点, 每个连通块肯定通过特殊点连到其他连通块, 我们把有最大值的特殊点当作根, 然后其他点直接接在这个点中, 形成菊花图. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<…
题目链接:http://codeforces.com/contest/755/problem/D 题意:一个n边形,从1号点开始,每次走到x+k的位置如果x+k>n则到x+k-n的位置,问每次留下来的路径把这个多边形划分成了几个部分. 很明显只要求x到x+k位置之间的点有几个入度就行了,而且只要求小区间内除去两点剩下的点的入度即可. 不需要考虑x或x+k点到该点的入度因为更本不可能从x或x+k到该点. 所以可以将k值稍微优化一下全都统一到k<n/2,这不影响结果因为假设5个点1到3,k=2.5…
题目链接:点击打开链接 Imp is in a magic forest, where xorangles grow (wut?) A xorangle of order n is such a non-degenerate triangle, that lengths of its sides are integers not exceeding n, and the xor-sum of the lengths is equal to zero. Imp has to count the n…
题目大意: 有两个人轮流说单词,已经说过的单词不能再说.给出两人掌握的不同的单词,两人可能掌握相同的单词,但是这个单词也只能说一边.问在两人都是最优策略下先手是否必胜. 题解: 我们发现最优策略一定是先说两人都掌握的单词. 所以我们求出所有同时被掌握的单词 然后根据这种单词的奇偶性来判断即可. 求的时候写了个Trie... 不过好像直接暴力也可以.. #include <cstdio> #include <cstring> #include <algorithm> us…
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 找到出口到每个点的最短距离. 设你到出口的最短距离为temp 那么如果某个人到终点的距离<=temp,则他们肯定能遇到你 因为他们可以在终点等你.. 但是如果某个人到终点的距离>temp,那么他们肯定不可能在某个时刻和你遇到 因为如果可以在某个时刻与你遇到的话,那他可以接下来跟着你走,那么他到终点的距离肯定是和你到终点的距离是一样的. 而它到终点的距离又大于你到终点的距离 产生了矛盾,所以不可能. [代码] #include <b…
每次连线,起点和终点之间,每一个被点亮的点,这些点都能连出去两条线,因此可以增加的块数+2(1这个点除外,因为只有连出的点没有连进的点),计算起点和终点之间有几个点被点亮即可,然后1这个点特判一下.感觉,可以用线段树维护..不过这题还是有规律的,每转过一圈,两线之间的点数就会加1,然后O(n)扫一遍就行了.注意答案会爆int. 代码如下: #include <bits/stdc++.h> using namespace std; ; typedef long long ll; int n,k;…
题意:A和B两人每人都熟悉一些单词.A先开始,每人说一个单词,单词不能与两人之前说过的所有单词重复,谁无话可说谁输.两人可能有共同会的单词. 分析:因为要让对方尽量无单词可说,所以每个人优先说的都是两人共同会的单词,假设两人共同会的单词数为common. A会的单词数为n,B会的单词数为m. 1.common若为偶数,则两人说完共同会的单词后,若n-common>m-common,则A赢. 2.common若为奇数,则两人说完共同会的单词后,若n-common>m-common-1,则A赢.…
Content 给定无向图的 \(n\) 个点的父亲节点,求无向图的联通块个数. 数据范围:\(1\leqslant n\leqslant 10^4\). Solution 并查集模板题. 我们将在当前节点和它的父亲节点连在一起,然后看不同的祖先节点的个数即可. 没学过并查集的同学建议先去做 P3367 [模板]并查集. Code #include <cstdio> #include <algorithm> #include <cstring> #include <…
1.PolandBall and Hypothesis 题面在这里! 大意就是让你找一个m使得n*m+1是一个合数. 首先对于1和2可以特判,是1输出3,是2输出4. 然后对于其他所有的n,我们都可以非常快的找到一个最小的与它互质的质数p(考虑反证法),并且满足p<n. 这样就相当与解一个同余方程 n*m = p-1 (mod p) , 解出的m可以保证 n*m+1 是 p 的倍数,也就是合数了. 又因为gcd(p,n)==1,所以这个方程肯定有解,直接求一个 n 在mod p意义下的逆元然后乘…
B. Biridian Forest Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/problem/B Description You're a mikemon breeder currently in the middle of your journey to become a mikemon master. Your current obstacle is go through t…
D. Biridian Forest time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You're a mikemon breeder currently in the middle of your journey to become a mikemon master. Your current obstacle is go…
Building Forest CodeForces - 195E 这题意真是难懂啊...话说"An oriented weighted forest is an acyclic weighted digraph in which from each vertex at most one edge goes."这句话到底什么意思... 题意:有n个点要按照1-n的顺序依次插入一个带边权的森林(森林一开始没有任何点.边),第i+1行描述第i个点插入后的操作.如果某一行为(k,  v1, …
题目传送门 /* 题意:给出无向无环图,每一个点的度数和相邻点的异或和(a^b^c^....) 图论/位运算:其实这题很简单.类似拓扑排序,先把度数为1的先入对,每一次少一个度数 关键在于更新异或和,精髓:a ^ b = c -> a ^ c = b, b ^ c = a; */ #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <…
题目传送门 /* 题意:给出无向无环图,每一个点的度数和相邻点的异或和(a^b^c^....) 图论/位运算:其实这题很简单.类似拓扑排序,先把度数为1的先入对,每一次少一个度数 关键在于更新异或和,精髓:a ^ b = c -> a ^ c = b, b ^ c = a; */ #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already sa…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integ…
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard output PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve i…
题目链接: 题目 A. Misha and Forest time limit per test 1 second memory limit per test 256 megabytes 问题描述 Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n ver…
http://codeforces.com/problemset/problem/755/D 每次新画一条对角线的时候,考虑其跨越了几条原有的对角线. 可以用树状数组区间修改点查询来维护多边形的顶点.答案每次增加 新对角线的左端点在多少个区间内+右端点在多少个区间内+1,每次把新画的对角线所覆盖的较小区间内部的每个点加1即可.注意,一定要是较小的区间,因为这样才能保证其左右端点不同时在区间内,不会重复统计. #include<cstdio> #include<algorithm>…
题目链接: F. PolandBall and Gifts time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output It's Christmas time! PolandBall and his friends will be giving themselves gifts. There are n Balls overall.…
B. Magic Forest time limit per test 1 second memory limit per test 256 megabytes Problem Description Imp is in a magic forest, where xorangles grow (wut?) A xorangle of order n is such a non-degenerate triangle, that lengths of its sides are integers…