题意:问两个迷宫是否存在公共最短路. 题解:两个反向bfs建立层次图,一遍正向bfs寻找公共最短路 #include<cstdio> #include<cstring> #include<queue> using namespace std; +; int d1[maxn][maxn]; int d2[maxn][maxn]; char g1[maxn][maxn]; char g2[maxn][maxn]; int n,m; struct node{ int x,y;…
CF Gym 102028G Shortest Paths on Random Forests 抄题解×1 蒯板子真jir舒服. 构造生成函数,\(F(n)\)表示\(n\)个点的森林数量(本题都用EGF).怎么求呢 \(f(n)=n^{n-2}\)表示\(n\)个点的树数量,根据\(\exp\)定义,\(e^x=\sum_{i=0}^{\infty}\frac{x^i}{i!}\).那么\(F=\exp f\),感性理解就是如果选\(i\)个联通块拼起来就除以\(i!\),很对的样子. 那么期…
E. Two Labyrinths Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/E Description A labyrinth is the rectangular grid, each of the cells of which is either free or wall, and it's possible to move only between free…
题目链接:http://codeforces.com/gym/100187/problem/E 题解:一开始做的时候是将两幅图合并,然后直接bfs看是否能到达终点.但这种做法的错的,因为走出来的路对于两幅图来说不一定都是最短的.正确做法: 第一步:分别用bfs求出两图的最短路. 第二步:如果最短路长度一样.则将两幅图合并,再bfs,如果能走到终点,且最短路长度仍然等于未合并前的长度,则YES: 否则NO. 学习之处: 求两个或多个事物所共有的东西,其实就是求交集. 代码如下: #include<…
题目:http://codeforces.com/gym/101933/problem/K 其实每个点的颜色只要和父亲不一样即可: 所以至多 i 种颜色就是 \( i * (i-1)^{n-1} \),设为 \( f(i) \),设恰好 i 种颜色为 \( g(i) \) 那么 \( f(i) = \sum\limits_{j=0}^{i} C_{i}^{j} * g(j) \) 二项式反演得到 \( g(i) = \sum\limits_{j=0}^{k} (-1)^{k-j} * C_{k}…
题目: Description standard input/output As most of you know, the Arab Academy for Science and Technology and Maritime Transport in Alexandria, Egypt, hosts the ACPC Headquarters in the Regional Informatics Center (RIC), and it has been supporting our r…
传送门 A. Ariel time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output King Triton really likes watching sport competitions on TV. But much more Triton likes watching live competitions. So Triton de…
传送门 E. Epic Fail of a Genie time limit per test 0.5 seconds memory limit per test 64 megabytes input standard input output standard output Aladdin had found a new shiny lamp and has started polishing it with his hands. Suddenly a mysterious genie app…
题意:龙要制作n个茶,每个茶的配方是一个字符串,两个字符串之间有一个差值,这个差值为两个字符串每个对应字母之间差的绝对值的最大值,求制作所有茶时获得的所有差值中的最大值. 解法:克鲁斯卡尔.将茶的配方作为点,将每两个点之间的差值作为边权,求最小生成树,这棵树中最大的边即为答案. 代码: #include<stdio.h> #include<iostream> #include<algorithm> #include<string> #include<s…
题意:王子每月买m个灯泡给n个房间换灯泡,如果当前有的灯泡数够列表的第一个房间换的就全换,直到灯泡不够为止,给出q个查询,查询x月已经换好几个房子,手里还剩多少灯泡. 解法:水题……小模拟. 代码: #include<stdio.h> #include<iostream> #include<algorithm> #include<string> #include<string.h> #include<math.h> #include&…