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. kafka java api生产者

    import java.util.HashMap; import java.util.List;import java.util.Map;import java.util.Properties; im ...

  2. [转+补]Android打包so后魅族5中安装运行崩溃问题的解决方法

    上周在做噪音检测so集成中,遇到不同的so库打包到 APK 时,安装在某些机器上,出现 java.lang.UnsatisfiedLinkError 加载失败. 为此,深究了一下原理,和给出了解决方案 ...

  3. linux服务器上的jenkins远程触发构建windows server 2012服务器上的jenkins任务

    本文来自:https://blog.csdn.net/huashao0602/article/details/53318295  非常感谢原博主,亲测可行,这是我做CI持续集成试过的第6套方案了! 背 ...

  4. python中中括号中的负数

    >>> a="a,b,c,d,e">>> a.split(",")[0:2]['a', 'b']>>> a ...

  5. RunTests.sh && RunIPhoneSecurityd.sh

    https://github.com/gh-unit/gh-unit/blob/master/Scripts/RunTests.sh     #!/bin/sh   # If we aren't ru ...

  6. 精仿百思不得姐客户端应用iOS源码

    XFBaiSiBuDeJie 高仿百思不得姐客户端 初次学习使用RAC,还不是怎么熟悉,使用的仍是MVC模式,MVVM还在摸索中... 如果大家觉得还不错,请给颗星星支持下~~~ 程序中使用到的库 A ...

  7. 签名ipa,让其它手机也安装

    开发的时候,需要将app让其它人装上测试,虽然通过xcode可以使用编译进去,但是仍显不方便. 网上有个工具, http://code.google.com/p/iresign/ 通过这个工具,使用自 ...

  8. linux下使用OpenCV的一些问题

    完整正确的代码如下: import cv2 import numpy as np image = cv2.imread('Pictures/a.png') cv2.imshow('original_i ...

  9. k8s集群介绍

    Kubernetes集群组件 一个典型的Kubernetes集群由多个工作节点和一个集群控制节点,以及一个集群状态存储系统etcd组成.其中Master节点负责整个集群管理工作,为集群提供管理接口,并 ...

  10. java web.xml被文件加载过程及加载顺序小结

    web.xml加载过程(步骤): 1.启动WEB项目的时候,容器(如:Tomcat)会去读它的配置文件web.xml.读两个节点: <listener></listener> ...