HDU2612 BFS】的更多相关文章

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2612 , 一道比较简单的广搜(BFS)题目. 算法: 设置两个dist[][]数组,记录Y和M到几个KFC的距离,最后求两个dist的和的最小值即可. 还有,Y是可以走M的位置的,同理,M也可以走Y的位置,不用纠结这个问题.有一点要注意的就是有的KFC是Y或M无法到达的,所以在最后求最小值的时候要注意这个KFC是否访问过. #include <iostream> #include <cstd…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2612 题意:求2个点到任意一个KFC的距离之和,使其最小. 分析:由两个点出发分别两次bfs,求得到每个KFC的距离,再枚举每个KFC求得最小距离和即可.刚开始以为KFC不能通过,wa了一次,坑... #include <cstdio> #include <cstring> #include <cmath> #include <iostream> #includ…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2612 思路: 裸的BFS,对于Y,M分别进行BFS,求出其分别到达各个点的最小时间: 然后对于@的点,将两者的最小时间相加即为到达此点的总时间,遍历所有@点,更新结果即可: 代码: #include<iostream> #include<cstdlib> #include<cstdio> #include<cstring> #include<queue&g…
#include<stdio.h>#include<string.h>#include<queue>#define INF 0x3f3f3f3fusing namespace std;//hdu2612,Y,M不能走 int s[210][210],lg[210][210],lg1[210][210];int n,m;struct node{ int x;//hang int y;//lie}a,b,d[4050];int bfs1(int a3,int b3){ qu…
我要被这个好用的memset气死了...... 真香 #include <cstring> #include <string> int main () { ]; memset(a, "真香", sizeof(a)); } 这道题也是出现了和昨天一样的情况,半小时写完,改bug改了1个小时,结果最后啸神说memeset不能随便给大数赋值,结果一改就改对了emm,真的是要被自己菜死了. 本题大意:给定一张地图,Y和M同时走向附近的KFC,找出Y和M距离和最短的KFC…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2612 Find a way Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 17047    Accepted Submission(s): 5486 Problem Description Pass a year learning in…
Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Ningbo one year, yifenfei have many people to meet. Especially a good friend Merceki. Yifenfei’s home is at the countryside, but Merceki’s home is in the center of c…
题目链接:hdu2612 思路:题意是求两个人到某一个KFC花费时间和最小,其实就是求最短距离和,用两个BFS,分别以两个人为起点,分别记录下两人到每个KFC的距离,然后求出最小的和 #include<stdio.h> #include<string.h> #include<queue> #include<algorithm> #define N 205 using namespace std; char map[N][N]; int v[N][N],ans…
图的遍历的定义: 从图的某个顶点出发访问遍图中所有顶点,且每个顶点仅被访问一次.(连通图与非连通图) 深度优先遍历(DFS): 1.访问指定的起始顶点: 2.若当前访问的顶点的邻接顶点有未被访问的,则任选一个访问之:反之,退回到最近访问过的顶点:直到与起始顶点相通的全部顶点都访问完毕: 3.若此时图中尚有顶点未被访问,则再选其中一个顶点作为起始顶点并访问之,转 2: 反之,遍历结束. 连通图的深度优先遍历类似于树的先根遍历 如何判别V的邻接点是否被访问? 解决办法:为每个顶点设立一个“访问标志”…
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…