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版全新上市,卡巴斯基依旧为大家奉上满足您所有需求的安全软件产品,为不同年龄层.不同人群给予全方位保护,同时延续卡 ...
随机推荐
- Sql Server的两个小技巧
创建表结构 CREATE TABLE test( ,) NOT NULL PRIMARY KEY, ) COLLATE Chinese_PRC_CI_AS NULL, createdTime DATE ...
- plpgsql 数组、JSON相关
Function Return Type Description Example Result array_append(anyarray,anyelement) anyarray append an ...
- 解决android studio设置版本号
获取版本号代码 /** * 获取版本号 * @return 当前应用的版本号 */ public static String getVersion(Context context) { try { P ...
- 单源最短路SPFA
#include<iostream> #include<queue> #include<cstring> #define INF 0x3f3f3f3f using ...
- CentOS7——防火墙设置
1.查看firewall服务状态 systemctl status firewalld 2.查看firewall的状态firewall-cmd --state 3.开启.重启.关闭.firewalld ...
- navicat 常用快捷键
1.ctrl+q 打开查询窗口 2.ctrl+/ 注释sql语句3.ctrl+shift +/ 解除注释4.ctrl+r 运行查询窗口的 ...
- CPP-基础:关于引用
1.什么是“引用”?申明和使用“引用”要注意哪些问题? 引用就是某个目标变量的“别名”(alias),对应用的操作与对变量直接操作效果完全相同. 申明一个引用的时候,切记要对其进行初始化. 引用声明完 ...
- Encryption-基础:base64加解密
环境:vc2003 .h /********** This library is free software; you can redistribute it and/or modify it und ...
- 解决IIS7多域名绑定同一物理目录,设置不同的默认文档的问题
IIS7多域名绑定同一物理目录,设置不同的默认文档是没办法设置的,因为在一个物理目录下只有一个web.config,并且IIS7把默认文档设置写在这里,导致所有域名的默认文档设置共享.解决方法:1.进 ...
- ASP.NET 开发人员不必担心 Node 的五大理由
哦别误会……我真的很喜欢 Node,而且我觉得它提出的概念和模式将在很长一段时间内,对服务端 Web 编程产生深远的影响.即使随着时间的推移 Node 过气了,我们肯定可以从下一个牛逼玩意身上或多或少 ...