博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【HDOJ】2102 A计划
阅读量:6861 次
发布时间:2019-06-26

本文共 1998 字,大约阅读时间需要 6 分钟。

BFS,不过有很多地方需要注意,比如传送机传送到另一个传送机。还有要注意格式。

1 #include 
2 #include
3 #include
4 #include
5 using namespace std; 6 7 typedef struct node_st{ 8 int x, y, s, t; 9 node_st() {}10 node_st(int ss, int xx, int yy, int tt) {s=ss;x=xx;y=yy;t=tt;}11 } node_st;12 13 char map[2][11][11];14 char visit[2][11][11];15 int direct[4][2] = {
{-1,0}, {
1,0}, {
0,-1}, {
0,1}};16 int n, m, time;17 18 19 bool bfs(int sx, int sy, int ss) {20 queue
nodes;21 int x, y, t, s;22 bool success = false;23 24 memset(visit, 0, sizeof(visit));25 visit[ss][sx][sy] = 1;26 nodes.push(node_st(ss,sx,sy,0));27 28 while ( !nodes.empty() ) {29 node_st node = nodes.front();30 if (node.t > time)31 break;32 if (map[node.s][node.x][node.y] == 'P') {33 success = true;34 break;35 }36 nodes.pop();37 for (int i=0; i<4; ++i) {38 x = node.x + direct[i][0];39 y = node.y + direct[i][1];40 s = node.s;41 t = node.t + 1;42 if (visit[s][x][y] || x<0 || x>=n || y<0 || y>=m)43 continue;44 if (map[s][x][y]=='#') {45 visit[s][x][y] = 1;46 s = !s;47 if (visit[s][x][y])48 continue;49 }50 if (map[s][x][y]=='#' || map[s][x][y]=='*') {51 visit[s][x][y] = 1;52 } else if (map[s][x][y]=='P' || map[s][x][y]=='.') {53 visit[s][x][y] = 1;54 nodes.push(node_st(s,x,y,t));55 }56 }57 }58 59 return success;60 }61 62 int main() {63 int case_n;64 int i;65 66 scanf("%d", &case_n);67 68 while (case_n--) {69 scanf("%d %d %d%*c", &n, &m, &time);70 for (i=0; i

 

 

转载于:https://www.cnblogs.com/bombe1013/p/3679035.html

你可能感兴趣的文章
Apache -- phpmyadmin导入文件过大
查看>>
我的友情链接
查看>>
一分钟看懂Docker的网络模式和跨主机通信
查看>>
数据中悲观锁和乐观锁的理解
查看>>
能想到登录失败是这原因么
查看>>
Shiro 权限管理filterChainDefinitions过滤器配置
查看>>
我的友情链接
查看>>
Python 文件I/Oday14
查看>>
回忆Spring IOC 几个注解&简单示例
查看>>
及时更新网卡驱动可使无线网络更稳定
查看>>
在if中赋值,但在if外却提示“使用了未赋值的局部变量”
查看>>
MapReduce源码之OutputFormat
查看>>
资质申报 - 系统集成企业资质等级评定条件实施细则
查看>>
近一个月的面试总结
查看>>
eclipse安装插件
查看>>
perl 非贪婪正则匹配 mysql 导出指定字段
查看>>
Android状态栏黑色字体
查看>>
MySQL主从复制之主库宕机处理
查看>>
Spring Cloud Eureka 源码分析(二) 客户端启动过程
查看>>
LAMP
查看>>