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版全新上市,卡巴斯基依旧为大家奉上满足您所有需求的安全软件产品,为不同年龄层.不同人群给予全方位保护,同时延续卡 ...
随机推荐
- java设计模式--建造模式
建造模式 建造模式属于对象创建型模式,建造模式的目的为将复杂对象的构建过程与其部件实现方式分离,使得同样的构建过程可以有不同的表示,同时相同的构建过程也能够适用于不同的部件实现方式. 建造模式的适用性 ...
- GIMP 无法设置中文的问题解决
首先按照网上说的安装了language-pack-gnome-zh-hant 参考链接:http://www.ubuntu-tw.org/modules/newbb/viewtopic.php?top ...
- vs2013编译过程中,错误 59 error C4996: 'GetVersionExW': 被声明为已否决
好几次碰到这个错误,必须mark 一下!!!!!Project Properties > Configuration Properties > C/C++ > General > ...
- (一)SpringMVC之警告: No mapping found for HTTP request with URI
这个警告往往是因为url路径不正确. 所以从三个地方下手: 1.springmvc-config.xml中的配置handle,看看是不是因为handle没有配置导致的. 2.如果是使用注解的方式的话, ...
- SAP云平台,区块链,超级账本和智能合约
前一篇文章<Hyperledger Fabric on SAP Cloud Platform>,我的同事Aviva已经给大家介绍了基于区块链技术的超级账本(Hyperledger)的一些概 ...
- [洛谷P4556][BZOJ3307]雨天的尾巴-T3订正
线段树合并+树上差分 题目链接(···) 「简单」「一般」——其实「一般」也只多一个离散化 考试时想法看>这里< 总思路:先存所有的操作,离散化,然后用树上差分解决修改,用权值线段树维护每 ...
- maven项目创建(eclipse配置
Eclipse相关配置: eclipse 设置默认编码为Utf-8 需要设置的几处地方为: Window --> Preferences --> General --> Conten ...
- jExcelAPI导入导出excel
MS的电子表格(Excel)是Office的重要成员,是保存统计数据的一种常用格式.作为办公文档,势必要涉及到的电子文档的交换,Excel是一种在企业中非常通用的文件格式,打印和管理也比较方便.在 ...
- SVN中检出(check out) 跟导出(export) 的区别
SVN中检出(check out) 和导出(export) 的区别?观点一:SVN是常用的一种常见的版本控制软件.SVN中检出(check SVN中检出(check out) 和导出(export ...
- Spring框架针对dao层的jdbcTemplate操作crud之delete删除数据库操作 Spring相关Jar包下载
首先,找齐Spring框架中IoC功能.aop功能.JdbcTemplate功能所需的jar包,当前13个Jar包 1.Spring压缩包中的四个核心JAR包,实现IoC控制反转的根据xml配置文件或 ...