codeforces 689B B. Mike and Shortcuts(bfs)】的更多相关文章

题目链接: B. Mike and Shortcuts time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some…
B. Mike and Shortcuts 题目连接: http://www.codeforces.com/contest/689/problem/B Description Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city. City consists of n inter…
题目链接:http://codeforces.com/problemset/problem/689/B 题目大意: 留坑 明天中秋~…
原题: Description Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city. City consists of n intersections numbered from 1 to n. Mike starts walking from his house locate…
Mike and Shortcuts 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/F Description Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city. City consists of n i…
B. Mike and Shortcuts time limit per test: 3 seconds memory limit per test: 256 megabytes input: standard input output: standard output Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some si…
B. Mike and Shortcuts time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight…
codeforces 689 Mike and Shortcuts(最短路) 原题 任意两点的距离是序号差,那么相邻点之间建边即可,同时加上题目提供的边 跑一遍dijkstra可得1点到每个点的最短路,时间复杂度是O(mlogm) #include <cstdio> #include <iostream> #include <cstring> #include <queue> #include <vector> using namespace s…
B. Mike and Shortcuts time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight…
目录 Codeforces 547C/548E - Mike and Foam 题解 前置芝士 - 容斥原理 题意 想法(口胡) 做法 程序 感谢 Codeforces 547C/548E - Mike and Foam 题解 前置芝士 - 容斥原理 容斥原理是简单的小学奥数求多个集合的并集的算法,最基本的思想大概是如下内容: 这是一道简单例题:有\(10\)个学生喜欢唱歌,有\(15\)个学生喜欢跳舞,有\(5\)个学生两种活动都喜欢,没有不喜欢前述两种活动的学生,那么一共有多少个学生呢? 相…
题目大意:给出n个点,两点间的常规路为双向路,路长为两点之间的差的绝对值,第二行为捷径,捷径为单向路(第i个点到ai点),距离为1.问1到各个点之间的最短距离. 题目思路:SPFA求最短路 #include<iostream> #include<algorithm> #include<cstring> #include<vector> #include<stdio.h> #include<stdlib.h> #include<q…
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…
https://vjudge.net/problem/CodeForces-516B 题意 在一个n*m图中放1*2或者2*1的长方形,问是否存在唯一的方法填满图中的‘.’ 分析 如果要有唯一的方案,那么必定存在度为一的点,因为只有这样,把这一格以及它相邻的涂掉的方案才唯一,然后可能产生新的度为一的可行点,不断更新,bfs寻找这样的点.最后检测一遍是否还有‘.'存在即可. #include<iostream> #include<cmath> #include<cstring&…
http://codeforces.com/problemset/problem/548/B Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column n…
传送门: http://codeforces.com/problemset/problem/616/C C. The Labyrinth time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a rectangular field of n × m cells. Each cell is either em…
题目链接 http://codeforces.com/problemset/problem/580/C 题意 根节点是 1 然后所有的叶子结点都是饭店 从根节点到叶子结点的路径上 如果存在 大于m 个 连续的结点都有猫 那么这条路径就是不可行的 求 最后能到达几个饭店 思路 BFS 就可以了 一层一层往下搜 但是要注意 这个输入的时候 xi yi 没有说 那个是父节点 哪个是儿子结点 那就都给它进去 也就是说 每个结点存的结点里面 有一个结点是自己的父亲结点 用visit[] 访问标记一下就可以…
有毒,自从上次选拔赛(哭哭)一个垃圾bfs写错之后,每次写bfs都要WA几发...好吧,其实也就这一次... 小白说的对,还是代码能力不足... 非常不足... 题目链接: http://codeforces.com/contest/659/problem/F 题意: n*m的格子,每个格子一个数,必须从格子中减去任意一个小于等于这个数的数. 给定数字k,要求: 剩下的格子数字和为k. 所有非零的格子的数字应该相同. 至少一个格子的数字没有改变. 含有非零数字的格子应该连通. 分析: 枚举每个能…
链接 Codeforces 677D Vanya and Treasure 题意 n*m中有p个type,经过了任意一个 type=i 的各自才能打开 type=i+1 的钥匙,最初有type=1的钥匙, 问拿到type=p的钥匙最少需要走多少步 思路 第一想法就是按type来递推, 将type相同的存到一起,dp[i][j]=min(dp[i][j], dp[k][l]+distance([i][j], [k][l])),其中 a[i][j] = a[k][l]+1. 但这样type相同的个数…
题目链接:http://codeforces.com/contest/591/problem/E 题意:有3个数字表示3个城市,每种城市都是相互连通的,然后不同种的城市不一定联通,'.'表示可以建设道路‘#’表示 不能,问最短建设多少道路能够让3种城市都联通起来 题解:直接bfs一遍所有类型的城市,bfs的同时更新第i类城市到(x,y)点的最短距离,更新第i类城市到第j类城市的距离 具体看一下代码. #include <iostream> #include <cstring> #i…
 Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing s…
D. Phillip and Trains time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The mobile application store has a new game called "Subway Roller". The protagonist of the game Philip is located…
原题: Description Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's define f([l, r]) = r - l + 1 to be the number of integer points in the segment [l, r] with l ≤ r (say that ). Y…
原题: Description While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, loc…
正解貌似是大暴搜? 首先我们考虑这是一个二分图,建立网络流模型后很容易得出一个算法 S->行 容量为Num[X]/2; 行->列 容量为1 且要求(x,y)这个点存在 列->T 容量为Num[Y]/2 这样子跑网络流之后我们就得到了一组解 但是我们考虑输出方案 对于每一行,如果Num[X]为偶数,那么显然输出方案是正确的 但是如果Num[x]为奇数,多出的那个显然既有可能是红的也可能是蓝的 但关键是我们不能确定他是红的或者蓝的,因为他的状态也会影响对应的列 同样,列的考虑也是同理 所以我…
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u   Description Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible! Aside from loving sweet things, thieves from this…
D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it…
One day Greg and his friends were walking in the forest. Overall there were n people walking, including Greg. Soon he found himself in front of a river. The guys immediately decided to get across the river. Luckily, there was a boat by the river bank…
题意:给出u,v,p,对u可以进行三种变化: 1.u=(u+1)%p ; 2.u = (u+p-1)%p;  3.u = 模p下的逆元.问通过几步可以使u变成v,并且给出每一步的操作. 分析:朴素的bfs或dfs会超时或炸栈,考虑用双向bfs头尾同时搜.用map存每个数的访问状态和对应的操作编号,正向搜步长为正,反向搜步长为负.反向搜的时候要注意对应加减操作是反过来的. #include<stdio.h> #include<iostream> #include<cstring…
题意:给定上一个n*m的矩阵,你从(1,1)这个位置发出水平向的光,碰到#可以选择四个方向同时发光,或者直接穿过去, 问你用最少的#使得光能够到达 (n,m)并且方向水平向右. 析:很明显的一个最短路,但是矩阵有点大啊.1000*1000,普通的肯定要超时啊,所以先通过#把该该图的行和列建立成二分图, 然后再跑最短路,这样就简单多了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <c…
好久好久好久之前的一个题,今天翻cf,发现这个题没过,补一下. B. Mike and strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has n strings s1, s2, ..., sn each consisting of lowercase English letters. In one…