TOJ 2017: N-Credible Mazes
2017: N-Credible Mazes 
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<stdio.h>
#include<algorithm>
using namespace std;
int a[][],b[][],c[][];
int main()
{
int n,T=;
while(~scanf("%d",&n),n)
{
int i,j,k;
for(i=;;i++)
{
scanf("%d",&a[i][]);
if(a[i][]==-)break;
for(j=; j<n; j++)
scanf("%d",&a[i][j]);
for(j=; j<n; j++)
scanf("%d",&b[i][j]);
}
for(k=; k<i; k++)
for(j=; j<n; j++)
c[k][j]=;
c[][]=;
for(i=; i<k; i++)
{
int f=;
for(j=; j<n; j++)
if(a[i+][j]!=a[i][j])
{
f++;
if(abs(a[i+][j]-a[i][j])!=)break;
}
if(f<=&&j==n&&c[i][]==)c[i+][]=;
f=;
for(j=; j<n; j++)
if(b[i][j]!=a[i][j])
{
f++;
if(abs(b[i][j]-a[i][j])!=)break;
}
if(f<=&&j==n&&c[i][]==)c[i][]=;
f=;
for(j=; j<n; j++)
if(b[i+][j]!=b[i][j])
{
f++;
if(abs(b[i+][j]-b[i][j])!=)break;
}
if(f<=&&j==n&&c[i][]==)c[i+][]=;
f=;
for(j=; j<n; j++)
if(b[i+][j]!=a[i+][j])
{
f++;
if(abs(b[i+][j]-a[i+][j])!=)break;
}
if(f<=&&j==n&&c[i+][]==)c[i+][]=;
}
if(c[k-][]>=) printf("Maze #%d can be travelled\n",T++);
else printf("Maze #%d cannot be travelled\n",T++);
}
return ;
}
map+set维护
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
using namespace std;
map<int,vector<int> >M;
set<int>S;
int la(int &num,int n)
{
num=;
for(int i=; i<=n; i++)
{
int x;
scanf("%d",&x);
if(x==-)return ;
num=num*+x;
}
return ;
}
int dfs(int st,int ed)
{
if(st==ed)return ;
int l=M[st].size();
for(int i=; i<l; i++)
{
int v=M[st][i];
if(!S.count(v))
{
S.insert(v);
if(dfs(v,ed))return ;
}
}
return ;
}
int main()
{
int t=,n;
while(~scanf("%d",&n))
{
if(n==)
{
if(scanf("%d",&n)==EOF)
break;
}
M.clear(),S.clear();
int st,ed;
la(st,n);
la(ed,n);
int s,e;
while(la(s,n))
{
la(e,n);
M[s].push_back(e);
M[e].push_back(s);
}
if(dfs(st,ed))
printf("Maze #%d can be travelled\n",t++);
else
printf("Maze #%d cannot be travelled\n",t++);
}
return ;
}
网上的HDUac代码
#include<stdio.h>
#include<string.h>
int f,sum,e,s;
int a[],b[];
int mark[];
void dfs(int w)
{
int i;
if (w==e)
{
f=;
return ;
}
for (i=; i<=sum; i++)
if (mark[i]== && (a[i]==w || b[i]==w))
{
mark[i]=;
if (a[i]==w) dfs(b[i]);
else dfs(a[i]);
}
} int main()
{
int Case,i,j,n,x;
Case=;
while (scanf("%d",&n)!=EOF)
{
if (n==) break; Case++;
s=e=;
for (i=; i<=n; i++)
{
scanf("%d",&x);
s=s*+x;
}
for (i=; i<=n; i++)
{
scanf("%d",&x);
e=e*+x;
} sum=;
memset(a,,sizeof(a));
memset(b,,sizeof(b)); while (scanf("%d",&x)!=EOF)
{
if (x==-) break; sum++;
a[sum]=x;
for (i=; i<n; i++)
{
scanf("%d",&x);
a[sum]=a[sum]*+x;
}
for (i=; i<=n; i++)
{
scanf("%d",&x);
b[sum]=b[sum]*+x;
} }
f=;
memset(mark,,sizeof(mark));
dfs(s);
printf("Maze #%d ",Case);
if (f==)
printf("cannot be travelled\n");
else
printf("can be travelled\n");
}
return ;
}
TOJ 2017: N-Credible Mazes的更多相关文章
- CI Weekly #10 | 2017 DevOps 趋势预测
2016 年的最后几个工作日,我们对 flow.ci Android & iOS 项目做了一些优化与修复: iOS 镜像 cocoapods 版本更新: fir iOS上传插件时间问题修复: ...
- 猖獗的假新闻:2017年1月1日起iOS的APP必须使用HTTPS
一.假新闻如此猖獗 刚才一位老同事 打电话问:我们公司还是用的HTTP,马上就到2017年了,提交AppStore会被拒绝,怎么办? 公司里已经有很多人问过这个问题,回答一下: HTTP还是可以正常提 ...
- iOS的ATS配置 - 2017年前ATS规定的适配
苹果规定 从2017年1月1日起,新提交的 app 不允许使用NSAllowsArbitraryLoads来绕过ATS(全称:App Transport Security)的限制. 以前为了能兼容ht ...
- 深入研究Visual studio 2017 RC新特性
在[Xamarin+Prism开发详解三:Visual studio 2017 RC初体验]中分享了Visual studio 2017RC的大致情况,同时也发现大家对新的Visual Studio很 ...
- Xamarin+Prism开发详解三:Visual studio 2017 RC初体验
Visual studio 2017 RC出来一段时间了,最近有时间就想安装试试,随带分享一下安装使用体验. 1,卸载visual studio 2015 虽然可以同时安装visual studio ...
- Microsoft Visual Studio 2017 for Mac Preview 下载+安装+案例Demo
目录: 0. 前言 1. 在线安装器 2. 安装VS 3. HelloWorld 4. ASP.NET MVC 5. 软件下载 6. 结尾 0. 前言: 工作原因,上下班背着我的雷神,一个月瘦了10斤 ...
- Create an offline installation of Visual Studio 2017 RC
Create an offline installation of Visual Studio 2017 RC 2016年12月7日 ...
- .NET Core 2.0版本预计于2017年春季发布
英文原文: NET Core 2.0 Planned for Spring 2017 微软项目经理 Immo Landwerth 公布了即将推出的 .NET Core 2.0 版本的细节,该版本预计于 ...
- 卡巴斯基2017激活教程_卡巴斯基2017用授权文件KEY激活的方法
原创:天诺时空 更新时间:2016-11-09 2016年9月7日,卡巴斯基2017版全新上市,卡巴斯基依旧为大家奉上满足您所有需求的安全软件产品,为不同年龄层.不同人群给予全方位保护,同时延续卡 ...
随机推荐
- 服务器 未能加载文件或程序集“XXXX”或它的某一个依赖项。试图加载格式不正确的程序。
,本人采用的第一种解决办法解决,已解决 问题2: 在同一个服务器上想要一个IP有两个网址,配置端口号,给新端口号开权限
- [问题解决]Deepin环境变量设置无效解决
将环境变量的设置放在这里: gedit ~/.bashrc 详见参考: linux下如何设置环境变量PATH : http://blog.csdn.net/witsmakemen/article/d ...
- js3
举几个小例子: 1. 九九乘法表 var s = "<table>"; for (var i=1;i<=9;i++) { s += "<tr> ...
- Mybatis-Generator逆向生成Po,Mapper,XMLMAPPER(idea)
前文有一篇手工生成的说明,地址: http://www.cnblogs.com/xiaolive/p/4874605.html, 现在这个补充一下在idea里面的自动版本的数据库逆向生成工具: 一.g ...
- UVA 11374 Airport Express (最短路)
题目只有一条路径会发生改变. 常见的思路,预处理出S和T的两个单源最短路,然后枚举商业线,商业线两端一定是选择到s和t的最短路. 路径输出可以在求最短路的同时保存pa数组得到一棵最短路树,也可以用di ...
- valgrind测试程序内存泄漏问题
1.用wincap将valgrind放入系统任意路径下,解压 2. 登录主机后台在需要测试程序的路径下运行此行命令: /opt/valgrind/bin/valgrind ./itb(例) 3. 跑 ...
- POI读word doc 03 文件的两种方法
Apache poi的hwpf模块是专门用来对word doc文件进行读写操作的.在hwpf里面我们使用HWPFDocument来表示一个word doc文档.在HWPFDocument里面有这么几个 ...
- Xcode中的约束用法
这篇文章用几个简单的例子来介绍XCode6.1故事板中约束的使用方法. 现在iOS设备屏幕的尺寸也有很多种了,尤其是有了iPhone6 Plus以后,再不关注界面的尺寸适配就有点说不过去了. ...
- React初识整理(二)--生命周期的方法
React生命周期主要有7中: 1. componentWillMount() :组件将要挂载时触发 ,只调用1次 2. componentDidMount() :组件挂载完成时触发,只调用1次 3. ...
- luogu P1966 火柴排队 (逆序对)
luogu P1966 火柴排队 题目链接:https://www.luogu.org/problemnew/show/P1966 显然贪心的想,排名一样的数相减是最优的. 证明也很简单. 此处就不证 ...