#P8247. 皇室战争
皇室战争
Description
The training ground can be seen as an character matrix, where each cell is S, K, or ..
S is the "Princess" (Shen Jian You Xia), and K is a skeleton. As everyone knows, the Princess’s arrows can pierce through targets. (We treat the arrow’s range as a ray with infinite length.) Since skeletons are very fragile, they die after being hit once. It is known that all skeletons do not move. What is the minimum number of arrows she needs to shoot to kill all skeletons?
Assume all characters stand on points and have zero size.
Input Format
The first line contains two numbers, and .
Lines to each contain characters, representing skeletons K, empty cells ., and the Princess S. There is only one S.
Output Format
Output one number: the minimum number of arrows shot.
3 5
K...K
.K.K.
..S..
2
3 5
KKKKK
KKSKK
KKKKK
12
Hint
- Subtask 1 (15 points): .
- Subtask 2 (20 points): .
- Subtask 3 (35 points): .
- Subtask 4 (30 points): .
Both and are positive integers.
Explanation for Sample :

Translated by ChatGPT 5
京公网安备 11011102002149号