A1224 | [COCI-2011_2012-contest2]#4 OKRET
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Mirko has been learning to drive, but he still cannot make a U-turn in a narrow street. That’s why he has decided to go practice in a town where U-turns are forbidden everywhere. This prohibition can be marked by the following sign:
Mirko has soon figured out that his ideal town must not contain dead-end streets, since it is impossible to exit such a street without a U-turn (let us assume that Mirko cannot drive in reverse either). Write a program to analyse a town map and determine whether the town is suitable for Mirko (i.e. whether the town has any dead-end streets).
The town map is a table with R x C cells, where each cell is a building segment (denoted by X) or a road surface (denoted by a dot). From a road surface cell, Mirko can move to any of the surrounding four cells (up, down, left, or right), provided that it is also a road surface (i.e. not a building).
Formally, we will determine that a town is free of dead-end streets if, starting from any road surface cell and going in any of the possible directions, we can return to the starting cell without making a 180 degrees turn (changing our direction to the opposite one).
Mirko has soon figured out that his ideal town must not contain dead-end streets, since it is impossible to exit such a street without a U-turn (let us assume that Mirko cannot drive in reverse either). Write a program to analyse a town map and determine whether the town is suitable for Mirko (i.e. whether the town has any dead-end streets).
The town map is a table with R x C cells, where each cell is a building segment (denoted by X) or a road surface (denoted by a dot). From a road surface cell, Mirko can move to any of the surrounding four cells (up, down, left, or right), provided that it is also a road surface (i.e. not a building).
Formally, we will determine that a town is free of dead-end streets if, starting from any road surface cell and going in any of the possible directions, we can return to the starting cell without making a 180 degrees turn (changing our direction to the opposite one).
输入格式
The first line of input contains the positive integers R and C (3 ≤ R, C ≤ 10), the dimensions of the town.
Each of the next R lines contains C characters, with each character either “X” or “.”. These R x C characters represent the town map as described in the text above. At least two cells will be road surfaces, and all road surfaces will be connected (i.e. mutually reachable).
Each of the next R lines contains C characters, with each character either “X” or “.”. These R x C characters represent the town map as described in the text above. At least two cells will be road surfaces, and all road surfaces will be connected (i.e. mutually reachable).
输出格式
The first and only line of output must contain 0 if the town is free of dead-end streets, otherwise it must contain
1.
1.
输入输出样例
输入 #1
4 3 XXX X.X X.X XXX
输出 #1
1
输入 #2
5 5 XX.XX X...X ..... X...X XX.XX
输出 #2
1
输入 #3
3 9 ...XXX... .X.....X. ...XXX...
输出 #3
0
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted