ZOJ2913Bus Pass(BFS+set)】的更多相关文章

Bus Pass Time Limit: 5 Seconds      Memory Limit: 32768 KB You travel a lot by bus and the costs of all the seperate tickets are starting to add up. Therefore you want to see if it might be advantageous for you to buy a bus pass. The way the bus syst…
通过几道经典BFS例题阐述BFS思路 ZOJ2913-Bus Pass 题意:找一个center区域,使得center到所有公交线路最短,有等距的center则输出id最小的. 题解:经典的BFS,由公交线路最多只经过10*20个区域,而总区域数可达10^5个,因此应该从公交线路通过队列一层层向外扩展,最后判断一次center的位置即可. //选定一个center使得其到所有公交线路最短 //对所有公交线路进行BFS(公交线路比其他区域少得多) //Time:150Ms Memory:2840K…
题目描述 给出一个N行M列的地图,地图形成一个有N*M个格子的矩阵.地图中的空地用'.'表示.其中某些格子有怪兽,用'+'表示.某人要从起点格子'V'走到终点格子'J',他可以向上.下.左.右四个方向行走.因此,起点和终点之间可以有许多条路径.注意:即使是有怪兽的格子,他也可以走上去. 设路径上某个格子的坐标为(R,C),某个怪兽的坐标为(A,B),那么它们之间的曼哈顿距离定义为:|R-A| + |C-B| 显然,地图上可能有许多怪兽,路径上也可能途经许多格子,每个格子到每个怪兽都可以算出之间的…
题意  在全部城市中找一个中心满足这个中心到全部公交网站距离的最大值最小 输出最小距离和满足最小距离编号最小的中心 最基础的BFS  对每一个公交网站BFS  dis[i]表示编号为i的点到全部公交网站距离的最大值  bfs全然部网站后  dis[i]最小的点就是要求的点咯 #include<cstdio> #include<cstring> #include<queue> #include<set> using namespace std; typedef…
题目地址 因为最后要看的是到所有路线上的区域最大距离最小的中心点,所以可以采取遍历路线上所有的区域,对每个区域进行BFS的办法.为了更方便的在每一次BFS都遍历所有的区域,可以加一个reach数组,记录每个区域被第几站BFS过,进行过一次就将站数赋给reach.BFS时的"距离"类似于""等距线",一圈圈的往外面走. #include <cstdio> #include <queue> #include<cstring>…
1656: [Usaco2006 Jan] The Grove 树木 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 186  Solved: 118[Submit][Status][Discuss] Description The pasture contains a small, contiguous grove of trees that has no 'holes' in the middle of the it. Bessie wonders…
#1372 : 平方求和 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 对于一个非负整数n,最少需要几个完全平方数,使其和为n? 输入 输入包含多组数据.对于每组数据: 第一行是n:如果n为-1,表示输入结束.(0 <= n <= 1000000001) 输出 针对每组数据,输出最少需要的完全平方数. 样例输入 3 4 5 -1 样例输出 3 1 2 思路: 拿到这个题,我第一想到的是贪心,每次减去一个最大数的平方,但是有时候这样会得不到正确的答案,比如19 ,贪…
A Board Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 551   Accepted: 373 Description Dao was a simple two-player board game designed by Jeff Pickering and Ben van Buskirk at 1999. A variation of it, called S-Dao, is a one-player…
http://acm.hdu.edu.cn/showproblem.php?pid=5025 Saving Tang Monk Problem Description   <Journey to the West>(also <Monkey>) is one of the Four Great Classical Novels of Chinese literature. It was written by Wu Cheng'en during the Ming Dynasty.…
Description <Journey to the West>(also <Monkey>) is one of the Four Great Classical Novels of Chinese literature. It was written by Wu Cheng'en during the Ming Dynasty. In this novel, Monkey King Sun Wukong, pig Zhu Bajie and Sha Wujing, escor…