博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
TOJ 2017: N-Credible Mazes
阅读量:6244 次
发布时间:2019-06-22

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

2017: N-Credible Mazes 分享至QQ空间

Time Limit(Common/Java):1000MS/10000MS     Memory Limit:65536KByte
Total Submit: 6            Accepted:0

Description

An n-tersection is defined as a location in n-dimensional space, n being a positive integer, having all non-negative integer coordinates. For example, the location (1,2,3) represents an n-tersection in three dimensional space. Two n-tersections are said to be adjacent if they have the same number of dimensions and their coordinates differ by exactly 1 in a single dimension only. For example, (1,2,3) is adjacent to (0,2,3) and (2,2,3) and (1,2,4), but not to (2,3,3) or (3,2,3) or (1,2). An n-teresting space is defined as a collection of paths between adjacent n-tersections.

Finally, an n-credible maze is defined as an n-teresting space combined with two specific n-tersections in that space, one of which is identified as the starting n-tersection and the other as the ending n-tersection.

Input

The input file will consist of the descriptions of one or more n-credible mazes. The first line of the description will specify n, the dimension of the n-teresting space. (For this problem, n will not exceed 10, and all coordinate values will be less than 10.) The next line will contain 2n non-negative integers, the first n of which describe the starting n-tersection, least dimension first, and the next n of which describe the ending n-tersection. Next will be a nonnegative number of lines containing 2n non-negative integers each, identifying paths between adjacent n-tersections in the n-teresting space. The list is terminated by a line containing only the value ?C1. Several such maze descriptions may be present in the file. The end of the input is signalled by space dimension of zero. No further data will follow this terminating zero.

Output

For each maze output it's position in the input; e.g. the first maze is "Maze #1", the second is "Maze #2", etc. If it is possible to travel through the n-credible maze's n-teresting space from the starting n-tersection to the ending n-tersection, also output "can be travelled" on the same line. If such travel is not possible, output "cannot be travelled" instead.

Sample Input

 

2

0 0 2 2
0 0 0 1
0 1 0 2
0 2 1 2
1 2 2 2
-1
3
1 1 1 1 2 3
1 1 2 1 1 3
1 1 3 1 2 3
1 1 1 1 1 0
1 1 0 1 0 0
1 0 0 0 0 0
-1
0

Sample Output

Maze #1 can be travelled

Maze #2 cannot be travelled
数据的锅,理解题意写的代码大概都是可以AC的

爆搜的代码

#include
#include
using namespace std;int a[1005][10],b[1005][10],c[1005][3];int main(){ int n,T=1; while(~scanf("%d",&n),n) { int i,j,k; for(i=0;;i++) { scanf("%d",&a[i][0]); if(a[i][0]==-1)break; for(j=1; j
=1) printf("Maze #%d can be travelled\n",T++); else printf("Maze #%d cannot be travelled\n",T++); } return 0;}

map+set维护

#include
#include
#include
#include
using namespace std;map
>M;set
S;int la(int &num,int n){ num=0; for(int i=1; i<=n; i++) { int x; scanf("%d",&x); if(x==-1)return 0; num=num*10+x; } return 1;}int dfs(int st,int ed){ if(st==ed)return 1; int l=M[st].size(); for(int i=0; i

网上的HDUac代码

#include
#include
int f,sum,e,s;int a[10010],b[10010];int mark[10010];void dfs(int w){ int i; if (w==e) { f=1; return ; } for (i=1; i<=sum; i++) if (mark[i]==0 && (a[i]==w || b[i]==w)) { mark[i]=1; if (a[i]==w) dfs(b[i]); else dfs(a[i]); }}int main(){ int Case,i,j,n,x; Case=0; while (scanf("%d",&n)!=EOF) { if (n==0) break; Case++; s=e=0; for (i=1; i<=n; i++) { scanf("%d",&x); s=s*10+x; } for (i=1; i<=n; i++) { scanf("%d",&x); e=e*10+x; } sum=0; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); while (scanf("%d",&x)!=EOF) { if (x==-1) break; sum++; a[sum]=x; for (i=1; i

 

转载于:https://www.cnblogs.com/BobHuang/p/7697718.html

你可能感兴趣的文章
linux之sed用法
查看>>
[转载] 全本张广泰——第十七回 夫人诱广泰 血溅洪洞县
查看>>
[转载] 财经郎眼20120326:房价降不下来的秘密
查看>>
[转载] 中国好声音120727
查看>>
我的Python之路【第一篇】:Python简介和入门
查看>>
Oracle11G DataGuard搭建记录
查看>>
python操作pymysql数据库
查看>>
POJ 3680 Intervals
查看>>
【总结整理】微信“不友好”设计其背后的逻辑---摘自人人都是产品经理
查看>>
51nod 1217 Minimum Modular
查看>>
.js 兼容 FireFox 和 IE 键盘事件
查看>>
java学习之部分笔记
查看>>
78. Subsets
查看>>
JavaScript高级之词法作用域和作用域链
查看>>
ServletConfig详解 (转载)
查看>>
oracle 查看用户所在的表空间
查看>>
CentOS配置sshd
查看>>
利用libevent的timer实现定时器interval
查看>>
接口的使用
查看>>
LeetCode 347. Top K Frequent Elements
查看>>