【Codeforces 1037D】Valid BFS?】的更多相关文章

[链接] 我是链接,点我呀:) [题意] 让你判断一个序列是否可能为一个bfs的序列 [题解] 先dfs出来每一层有多少个点,以及每个点是属于哪一层的. 每一层的bfs如果有先后顺序的话,下一层的节点的出队也是有先后顺序的 因此x是当前层只是一个简单的判断条件,还需要更深入的判断 也就是说它是不是应该在这个时候从队列中出来,也就是说它前面是不是应该有节点比它先出现. 我们需要记录每个节点(dep层)的priority值. 这个值表示了这个节点x它的直系儿子们(dep+1层)在所有dep+1层出现…
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=2000),问满足[数列长度是k && 数列中每一个元素arr[i]在1~n之间 && 数列中元素可以重复]的数列有多少个?结果对10^9+7取余 解题思路:dp[i][j]表示长度是j,最后一位是i的种数 if(kk%i==0) dp[kk][j+1]+=dp[i][j] #inc…
[题目链接]:http://codeforces.com/contest/796/problem/D [题意] 在一棵树上,保证每个点在距离d之内都有一个警察局; 让你删掉最多的边,使得剩下的森林仍然满足上述约束; [题解] 从每个警察局开始进行bfs; 这样每个路线第一次到达的点肯定是最短路; 所以bfs的时候遇到没访问过的点,就记录它被访问,即它被这个状态一开始的警察局所管辖(控制); 则可以想象每个警察局都同时往外扩张; 则每个警察局管的范围就确定是那些了; 则那些点肯定是到那个管辖它的警…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Vanya is doing his maths homework. He has an expression of form , where x1, x2, -, xn are digits from 1 to 9, and sign represents either a plus '…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan regi…
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…
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…
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the second soldier. Then the second…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output This is an interactive problem. In the interaction section below you will find the information about flushing the output. The New Year tree of h…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian i…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output The mobile application store has a new game called "Subway Roller". The protagonist of the game Philip is located in one end of the tunnel a…
[题目链接]:http://codeforces.com/contest/520/problem/B [题意] 给你一个数n; 对它进行乘2操作,或者是-1操作; 然后问你到达m需要的步骤数; [题解] 操作的过程中; 可能会大于m吧: 也不知道是多少倍; 但也没事,不差那一点时间. bfs [完整代码] #include <bits/stdc++.h> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,r…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length n whi…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length n whi…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical…
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q个操作; 有以下两种类型 ①将第i个连通块里面灯取反 ②询问你(x1,y1)(x2,y2)这个矩形区域内灯的权值的和; [题解] 要用到二维的树状数组; 取反操作只要O(1)就能完成; 即先不管它是什么,取反就是了; 然后在询问的时候,直接用二维树状数组累加; 这里的累加可能是减也可能是加; 也可能…
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小; [题解] 首先明确n<=2的时候是无解的. n>2之后都有解; 这里设 n2+b2=a2 则有 n2=a2−b2 也即 n2=(a+b)∗(a−b) 这里对n分两类讨论; ① n为奇数 则令 a−b=1 a+b=n2 这样 2∗a=n2+1 因为n是奇数所以右边是个偶数; 得出来的a就是整数了…
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出一个符合要求的序列; [题解] 这里 00和11可以确定出序列中0和1的个数; 但有边缘数据 00如果为0代表什么? ->没有0或者是有1个0 11如果为0代表什么? ->没有1或者是有1个1 对这两种情况需要特判一下(两种情况的特判需要用到01和10的数量) 看代码吧. 然后这两种情况排除之后;…
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; 则肯定要有一个点不走; ->哪个点呢; 就是排序之后,最左边或最右边那个点不走; 不可能是中间的点. 因为既然你要走的点不是最边上的点,那么你肯定会在去最边上的点的时候路过那个你选择不走的点; 这个点的选取就没有意义了: 然后对于两种情况; 还有两种可能,就是先往左一直(不回头不然更长)走然后再往…
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一个; 即b->a或是a>z; 然后使得剩下的字符串的字典序最小; [题解] 优先更改前面的字符; 所以遇到第一个不是a的字符->改! 从那个字符开始只要不是a就一直改就好; hack点: 有说 exactly once->也就是说 像 aaa 不能全都不改; 把最后那个a改成z(损失最…
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = Sj - Si f(i,j) = (i-j)^2 + (Si - Sj)^2 观察这个式子,我们发现可以用类似于平面最近点对的算法来求解该问题 [代码] #include<bits/stdc++.h> using namespace std; #define MAXN 100010 const…
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using namespace std; #define MAXN 200010 ,nx = -,len,i,rkb,rkc; ],tmp[MAXN<<]; template <typename T> inline void read(T &x) { ; x = ; char c = g…
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案是唯一的; 则输出那个方案,否则,输出不唯一; [题解] 记录每个点的度; 每个点的度,为这个点4个方向上空格的个数; 优先处理度数为1的点; 这些点的摆放方式肯定是唯一的; 摆完这些点(两个之后),与之相连的点的度数都减1: 看看有没有新的度数为1的点; 很像拓扑排序对吧. 最后看看占据的点是不是…
[题目链接]:http://codeforces.com/contest/515/problem/C [题意] 定义f(n)=n这个数各个位置上的数的阶乘的乘积; 给你a; 让你另外求一个不含0和1的最大的数字b; 使得f(a)==f(b) [题解] 对a的每一个大于1的数字进行分解; 看看它能够组合成的最多的比它小的数字的阶乘的乘积是哪些; 比如 4!=3!∗(2!)2 每个都找最多数目的:数目相同找大的数的组合; 求出2..9!的组合就好; 最后根据每个数字的分解方案; 求出所有的数字; 然…
[题目链接]:http://codeforces.com/contest/515/problem/B [题意] 第i天选择第i%n个男生,第i%m个女生,让他们一起去吃饭; 只要这一对中有一个人是开心状态,另外一个人也能变成开心状态; 且开心之后就一直开心了: 给你n个男生,m个女生的状态(是否开心); 问你是否到了某一天所有人都会变的开心: [题解] 那个i%n和i%m的循环肯定有循环节的; 找到那个循环节的长度; 每次在循环节内尝试用上述办法,看看有没有办法让某些人从不开心变为开心; 如果可…
[题目链接]:http://codeforces.com/contest/515/problem/A [题意] 每次只能走到相邻的四个格子中的一个; 告诉你最后走到了(a,b)走了多少步->s (你一开始在位置(0,0) 问你可不可能; [题解] 先算出从0,0走到(a,b)的步数(最短)->temp; 之后,如果s-temp为偶数就可行,否则不可行; (s< temp肯定不行); 为偶数的话,去了可以再回来. 没看到a,b能为负数.. [Number Of WA] 1 [完整代码] #…
[题目链接]:http://codeforces.com/contest/761/problem/E [题意] 给你一棵树,让你在平面上选定n个坐标; 使得这棵树的连接关系以二维坐标的形式展现出来; [题解] dfs来搞; 显然如果某个点的度数大于4就无解. 初始坐标为(0,0)然后每一层的边的长度变为上一层长度的1/2 初始层的长度为2 30   这样可以保证每层节点都不会和上一层的相交; 因为2 i >2 1 +2 2 +...+2 i−1   又因为最多只有30个节点,所以这么做肯定是可以…
[题目链接]:http://codeforces.com/contest/764/problem/D [题意] 给你n个矩形,以左下角坐标和右上角坐标的形式给出; (保证矩形的边长为奇数) 问你有没有染色方案,使得这n个矩形,任意两个相邻矩形的颜色不一样; (只有4种颜色可以选择); [题解] 因为矩形的边长为奇数; 所以对于左下角来说; 右上角的横纵坐标的奇偶性分别和左下角的横纵坐标的奇偶性都不同; (因为一个数加上奇数之后奇偶性发生改变); 按照这个原理; 我们只要考虑左下角那个坐标就好了:…
[题目链接]:http://codeforces.com/contest/792/problem/D [题意] 给你一棵满二叉树; 给你初始节点; 给你若干个往上走,左走,右走操作; 让你输出一系列操作结束之后节点的位置; [题解] 这个节点的标志方式类似树状数组; 用树状数组左走右走就好; L->x-=lowbit(x)/2; R->x+=lowbit(x)/2; U->先假设x是左儿子,然后依照规则求出父亲F,然后看看F的左儿子是不是真的是x,是的话爸爸就是F,否则x是右儿子,然后根…
[题目链接]:http://codeforces.com/contest/792/problem/C [题意] 让你删掉最少的数字使得剩下的数字%3==0 [题解] 看代码..内置题解了现在. [完整代码] #include <bits/stdc++.h> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define LL long long #define rep1(i,a…