A8825 | Rats
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Rats have bred to hundreds and hundreds in the basement of the store, owned by Vasily Petrovich. Vasily Petrovich may have not noticed their presence, but they got into the habit of sneaking into the warehouse and stealing food from there. Vasily Petrovich cannot put up with it anymore, he has to destroy the rats in the basement. Since mousetraps are outdated and do not help, and rat poison can poison inattentive people as well as rats, he chose a radical way: to blow up two grenades in the basement (he does not have more).
In this problem, we will present the shop basement as a rectangular table of $n×m$ cells. Some of the cells are occupied by walls, and the rest of them are empty. Vasily has been watching the rats and he found out that at a certain time they go to sleep, and all the time they sleep in the same places. He wants to blow up a grenade when this convenient time comes. On the plan of his basement, he marked cells with sleeping rats in them. Naturally, these cells are not occupied by walls.
Grenades can only blow up in a cell that is not occupied by a wall. The blast wave from a grenade distributes as follows. We assume that the grenade blast occurs at time 0. During this initial time only the cell where the grenade blew up gets 'clear'. If at time $t$ some cell is clear, then at time $t+1$ those side-neighbouring cells which are not occupied by the walls get clear too (some of them could have been cleared before). The blast wave distributes for exactly $d$ seconds, then it dies immediately.
An example of a distributing blast wave: Picture 1 shows the situation before the blast, and the following pictures show "clear" cells by time 0,1,2,3 and 4. Thus, the blast wave on the picture distributes for $d=4$ seconds.Vasily Petrovich wonders, whether he can choose two cells to blast the grenades so as to clear all cells with sleeping rats. Write the program that finds it out.
In this problem, we will present the shop basement as a rectangular table of $n×m$ cells. Some of the cells are occupied by walls, and the rest of them are empty. Vasily has been watching the rats and he found out that at a certain time they go to sleep, and all the time they sleep in the same places. He wants to blow up a grenade when this convenient time comes. On the plan of his basement, he marked cells with sleeping rats in them. Naturally, these cells are not occupied by walls.
Grenades can only blow up in a cell that is not occupied by a wall. The blast wave from a grenade distributes as follows. We assume that the grenade blast occurs at time 0. During this initial time only the cell where the grenade blew up gets 'clear'. If at time $t$ some cell is clear, then at time $t+1$ those side-neighbouring cells which are not occupied by the walls get clear too (some of them could have been cleared before). The blast wave distributes for exactly $d$ seconds, then it dies immediately.
An example of a distributing blast wave: Picture 1 shows the situation before the blast, and the following pictures show "clear" cells by time 0,1,2,3 and 4. Thus, the blast wave on the picture distributes for $d=4$ seconds.Vasily Petrovich wonders, whether he can choose two cells to blast the grenades so as to clear all cells with sleeping rats. Write the program that finds it out.
输入格式
The first line contains three integers $n$ , $m$ and $d$ , separated by single spaces ( $4<=n,m<=1000,1<=d<=8$ ). Next $n$ lines contain the table that represents the basement plan. Each row of the table consists of $m$ characters. Character "X" means that the corresponding cell is occupied by the wall, character "." represents a empty cell, character "R" represents a empty cell with sleeping rats.
It is guaranteed that the first and the last row, as well as the first and the last column consist of characters "X". The plan has at least two empty cells. There is at least one cell with sleeping rats.
It is guaranteed that the first and the last row, as well as the first and the last column consist of characters "X". The plan has at least two empty cells. There is at least one cell with sleeping rats.
输出格式
If it is impossible to blow up all cells with sleeping rats, print a single integer -1. Otherwise, print four space-separated integers $r_{1},c_{1},r_{2},c_{2}$ , that mean that one grenade should go off in cell $(r_{1},c_{1})$ , and the other one — in cell $(r_{2},c_{2})$ .
Consider the table rows numbered from top to bottom from 1 to $n$ and the table columns — from left to right from 1 to $m$ . As $r_{1}$ and $r_{2}$ represent the row numbers, and $c_{1}$ and $c_{2}$ represent the column numbers in the table, they should fit the limits: $1<=r_{1},r_{2}<=n,1<=c_{1},c_{2}<=m$ . It is forbidden to blow a grenade twice in the same cell. The blast waves of the grenades can intersect. It is possible that one grenade blast destroys no rats, and the other one destroys all of them.
Consider the table rows numbered from top to bottom from 1 to $n$ and the table columns — from left to right from 1 to $m$ . As $r_{1}$ and $r_{2}$ represent the row numbers, and $c_{1}$ and $c_{2}$ represent the column numbers in the table, they should fit the limits: $1<=r_{1},r_{2}<=n,1<=c_{1},c_{2}<=m$ . It is forbidden to blow a grenade twice in the same cell. The blast waves of the grenades can intersect. It is possible that one grenade blast destroys no rats, and the other one destroys all of them.
输入输出样例
输入 #1
4 4 1 XXXX XR.X X.RX XXXX
输出 #1
2 2 2 3
输入 #2
9 14 5 XXXXXXXXXXXXXX X....R...R...X X..R.........X X....RXR..R..X X..R...X.....X XR.R...X.....X X....XXR.....X X....R..R.R..X XXXXXXXXXXXXXX
输出 #2
2 3 6 9
输入 #3
7 7 1 XXXXXXX X.R.R.X X.....X X..X..X X..R..X X....RX XXXXXXX
输出 #3
-1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted