2017: N-Credible Mazes 

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<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的更多相关文章

  1. CI Weekly #10 | 2017 DevOps 趋势预测

    2016 年的最后几个工作日,我们对 flow.ci Android & iOS 项目做了一些优化与修复: iOS 镜像 cocoapods 版本更新: fir iOS上传插件时间问题修复: ...

  2. 猖獗的假新闻:2017年1月1日起iOS的APP必须使用HTTPS

    一.假新闻如此猖獗 刚才一位老同事 打电话问:我们公司还是用的HTTP,马上就到2017年了,提交AppStore会被拒绝,怎么办? 公司里已经有很多人问过这个问题,回答一下: HTTP还是可以正常提 ...

  3. iOS的ATS配置 - 2017年前ATS规定的适配

    苹果规定 从2017年1月1日起,新提交的 app 不允许使用NSAllowsArbitraryLoads来绕过ATS(全称:App Transport Security)的限制. 以前为了能兼容ht ...

  4. 深入研究Visual studio 2017 RC新特性

    在[Xamarin+Prism开发详解三:Visual studio 2017 RC初体验]中分享了Visual studio 2017RC的大致情况,同时也发现大家对新的Visual Studio很 ...

  5. Xamarin+Prism开发详解三:Visual studio 2017 RC初体验

    Visual studio 2017 RC出来一段时间了,最近有时间就想安装试试,随带分享一下安装使用体验. 1,卸载visual studio 2015 虽然可以同时安装visual studio ...

  6. Microsoft Visual Studio 2017 for Mac Preview 下载+安装+案例Demo

    目录: 0. 前言 1. 在线安装器 2. 安装VS 3. HelloWorld 4. ASP.NET MVC 5. 软件下载 6. 结尾 0. 前言: 工作原因,上下班背着我的雷神,一个月瘦了10斤 ...

  7. Create an offline installation of Visual Studio 2017 RC

    Create an offline installation of Visual Studio 2017 RC ‎2016‎年‎12‎月‎7‎日                             ...

  8. .NET Core 2.0版本预计于2017年春季发布

    英文原文: NET Core 2.0 Planned for Spring 2017 微软项目经理 Immo Landwerth 公布了即将推出的 .NET Core 2.0 版本的细节,该版本预计于 ...

  9. 卡巴斯基2017激活教程_卡巴斯基2017用授权文件KEY激活的方法

    原创:天诺时空 更新时间:2016-11-09   2016年9月7日,卡巴斯基2017版全新上市,卡巴斯基依旧为大家奉上满足您所有需求的安全软件产品,为不同年龄层.不同人群给予全方位保护,同时延续卡 ...

随机推荐

  1. listView onItemClick失效

    1.先检查list是否设置监听onItemClick事件 2.ListView中有按钮时,会使子项的onItemClick事件无效,如果onItemClick不能触发,在ListView子项目布局文件 ...

  2. Windows定时任务管理以及服务管理

    1.NSSM.exe https://nssm.cc/ 2.Topshelf 引用地址:https://www.cnblogs.com/guogangj/p/10093102.html#4136330

  3. select *from where 和select *from jion on 语句的差别

    https://zhidao.baidu.com/question/541791438.html select 学号 a,成绩 a,姓名 b from 成绩表 a,学生表 b where a.学号=b ...

  4. APPScan-简单操作流程

    图解安全扫描工具 AppScan使用   IBM Rational AppScan 是一个面向 Web 应用安全检测的自动化工具,使用它可以自动化检测 Web 应用的安全漏洞. 比如跨站点脚本攻击(C ...

  5. CAD交互绘制mcdbsolid对象(网页版)

    主要用到函数说明: _DMxDrawX::DrawSolid 绘McDbSolid对象.详细说明如下: 参数 说明 DOUBLE dX1 第一个点X DOUBLE dY1 第一个点Y DOUBLE d ...

  6. Java习题附答案

    第一章练习题(Java入门) 1.下列哪项不是JDK所包含的内容?(选一项)C 红色代表正确答案 A.Java编程语言 B.工具及工具的API C.Java EE扩展API D.Java平台虚拟机 2 ...

  7. selenium--Xpath定位

    前戏 前面介绍过了七种定位方式,今天来介绍最后一种,也是最强大,本人最常用的定位方式xpath Xpath 即为 xml 路径语言,它是一种用来确定 xml 文档中某部分位置的语言.Xpath 基于 ...

  8. BZOJ1009: [HNOI2008]GT考试 (矩阵快速幂 + DP)

    题意:求一个长度为n的数字字符串 (n <= 1e9) 不出现子串s的方案数 题解:用f i,j表示长度为i匹配到在子串j的答案 用kmp的失配函数预处理一下 然后这个转移每一个都是一样的 所以 ...

  9. 2、Task 使用 ContinueWith 而不要使用 Wait

    1.线程自旋:在阻塞线程的时候为了等待解锁(访问临界资源)(Sleep). 2.上下文切换:将处理器当前线程的状态保存到操作系统内部的线程对象中,然后再挑出一个就绪的线程,把上下文信息传递给处理器,然 ...

  10. 换个语言学一下 Golang (1)

    做技术的总是有些拗.这么多年一直在.net的框框里打转转.直到现在市场上.net工作越来越难找,项目越来越老才发现不做出改变不行了.就从学习Go开始吧. Go语言的特点 简洁.快速.安全 并行.有趣. ...