输油管道 纪中 1432 优美的暴力
来源:互联网 发布:sim800 网络连接失败 编辑:程序博客网 时间:2024/05/18 17:01
Description
请你帮忙设计一个从城市M到城市Z的输油管道,现在已经把整个区域划分为R行C列,每个单元格可能是空的也可能是以下7种基本管道之一:
油从城市M流向Z,‘+’型管道比较特殊,因为石油必须在两个方向(垂直和水平)上传输,如下图所示:
现在恐怖分子弄到了输油管道的设计图,并把其中一个单元格中的管道偷走了,请你帮忙找到偷走的管道的位置以及形状。
Input
第一行包含两个整数R和C(1<=R,C<=25)。
接下来R行每行C个字符描述被偷之后的形状,字符分为以下三种:
(1)‘.’表示空;
(2)字符‘|’(ASCII为124)、‘-’、‘+’、‘1’、‘2’、‘3’、‘4’描述管道的形状;
(3)‘M’和‘Z’表示城市,两个都是只出现一次。
输入保证石油的流向是唯一的,只有一个管道跟M和Z相连,除此此外,保证没有多余的管道,也就是说所有的管道在加进被偷的管道后一定都会被用上。
输入保证有解而且是唯一的。
分析
一堆case和if的水题。
代码
const dx:array[1..4] of longint=(-1,0,1,0); dy:array[1..4] of longint=(0,1,0,-1);var a:array[0..100,0..100] of longint; i,j,k:longint; n,m:longint; c:char; ans:longint;procedure bfs(x,y,xy,s:longint);var i,j,k:longint; x1,y1,x2,y2,s1:longint;begin j:=0; ans:=1; for i:=1 to 4 do begin if i=xy then continue; case i of 1:if (a[x+dx[i],y+dy[i]]=2)or(a[x+dx[i],y+dy[i]]=3)or(a[x+dx[i],y+dy[i]]=6) then continue; 2:if (a[x+dx[i],y+dy[i]]=1)or(a[x+dx[i],y+dy[i]]=2)or(a[x+dx[i],y+dy[i]]=5) then continue; 3:if (a[x+dx[i],y+dy[i]]=1)or(a[x+dx[i],y+dy[i]]=4)or(a[x+dx[i],y+dy[i]]=6) then continue; 4:if (a[x+dx[i],y+dy[i]]=4)or(a[x+dx[i],y+dy[i]]=3)or(a[x+dx[i],y+dy[i]]=5) then continue; end; if a[x+dx[i],y+dy[i]]<>0 then begin if j=1 then begin writeln(x,' ',y,' ','+'); exit; end; x2:=x+dx[i]; y2:=y+dy[i]; s1:=i; j:=1; end; end; if (xy=1) or (xy=3) then begin x1:=x+dx[xy]; y2:=y; end; if (xy=2) or (xy=4) then begin x1:=x; y1:=y1+dy[xy]; end; case xy of 1:begin if s1=3 then writeln(x,' ',y,' |'); if s1=2 then writeln(x,' ',y,' 2'); if s1=4 then writeln(x,' ',y,' 3'); end; 2:begin if s1=3 then writeln(x,' ',y,' 1'); if s1=1 then writeln(x,' ',y,' 2'); if s1=4 then writeln(x,' ',y,' -'); end; 3:begin if s1=1 then writeln(x,' ',y,' |'); if s1=2 then writeln(x,' ',y,' 1'); if s1=4 then writeln(x,' ',y,' 4'); end; 4:begin if s1=3 then writeln(x,' ',y,' 4'); if s1=2 then writeln(x,' ',y,' -'); if s1=1 then writeln(x,' ',y,' 3'); end; end;end;begin readln(n,m); for i:=1 to n do begin for j:=1 to m do begin read(c); case c of '|':a[i,j]:=5; '-':a[i,j]:=6; '+':a[i,j]:=7; '1':a[i,j]:=1; '2':a[i,j]:=2; '3':a[i,j]:=3; '4':a[i,j]:=4; '.':a[i,j]:=0; 'M':a[i,j]:=10; 'Z':a[i,j]:=10; end; end; readln; end; for i:=1 to n do for j:=1 to n do begin if a[i,j]=0 then continue; ans:=0; case a[i,j] of 1:begin if a[i,j+1]=0 then bfs(i,j+1,4,1); if a[i+1,j]=0 then bfs(i+1,j,1,1); end; 2:begin if a[i,j+1]=0 then bfs(i,j+1,4,2); if a[i-1,j]=0 then bfs(i-1,j,3,2); end; 3:begin if a[i,j-1]=0 then bfs(i,j-1,2,3); if a[i-1,j]=0 then bfs(i-1,j,3,3); end; 4:begin if a[i,j-1]=0 then bfs(i,j-1,2,4); if a[i+1,j]=0 then bfs(i+1,j,1,4); end; 5:begin if a[i-1,j]=0 then bfs(i-1,j,3,5); if a[i+1,j]=0 then bfs(i+1,j,1,5); end; 6:begin if a[i,j+1]=0 then bfs(i,j+1,4,6); if a[i,j-1]=0 then bfs(i,j-1,2,6); end; 7:begin if a[i,j+1]=0 then bfs(i,j+1,4,7); if a[i+1,j]=0 then bfs(i+1,j,1,7); if a[i,j-1]=0 then bfs(i,j-1,2,7); if a[i-1,j]=0 then bfs(i-1,j,3,7); end; end; if ans=1 then halt; end;end.
1 0
- 输油管道 纪中 1432 优美的暴力
- 输油管道_纪中1432_暴力
- 删除 纪中 1381 优美的暴力
- 数码问题 纪中 1433 优美的暴力
- HDU6127Hardchallenge(优美的暴力)
- HDU 5311 Hidden String (优美的暴力)
- 根 ssl 2668 优美的暴力
- 选数 ssl 2669 优美的暴力
- 输油管道的实现
- 输油管道
- 输油管道
- HDU 2017 多校联合训练赛6 1008 6103 Kirinriki 优美的暴力
- 网页与APP中那些优美的登陆表单
- 如何在python项目中更加优美的自定义常量
- 有关输油管道问题的用时限制
- 优美的祝词
- 优美的琴声
- 编写"优美"的SHELLCODE
- Activiti基础教程--06流程变量
- android入门:zxing学习笔记(四)
- Tag deep-learning 一大堆深度学习论文
- hdu 2196(树形dp)
- 欢迎使用CSDN-markdown编辑器
- 输油管道 纪中 1432 优美的暴力
- java——动态代理
- Yarn(MapReduce 2.0)下分布式缓存(DistributedCache)的注意事项
- 教你如何调用百度编辑器ueditor的上传图片、上传文件等模块
- C#操作SQL Server中的Image类型数据
- No grammar constraints (DTD or XML schema).....解决方法
- 提高项目33-矩阵相加
- C++/CLR Windows界面编程(一·)
- NSIS安装包脚本