A1168 | [COCI-2008_2009-contest5]#3 KRUSKA
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Aladdin has become bored of life at the palace. He has a steady job, his wife Jasmine, kids are on the way and life is becoming monotonous. Prompted by all this, he has decided to have one more adventure before settling down.
He has decided to find the Golden Pear, an extremely valuable legendary artifact that no one has been able to find.
The desert Aladdin is searching is can be modeled as an N×N grid of cells. Rows and columns are numbered 1 through N top to bottom and left to right. Some of the cells in the desert contain wizards that help Aladdin's quest in an unusual way.
Aladdin starts his quest in the top left corner of the desert on a Monday facing right. His movement involves repeating these steps:
1. If the current cell contains a wizard that is awake, then Aladdin turns 90 degrees left or right, depending on what the wizard says.
2. If moving forward would take Aladdin out of desert, he turns 180 degrees.
3. Aladdin moves forward one cell and it takes him exactly one day.
For each wizard we know his location and his activity schedule for each day of the week. The schedule is a string of exactly seven letters 'L', 'R' or 'S', each character telling us what the wizard does on one day of the week (starting with Monday). The letter 'L' means that Aladdin will be told to turn left, 'R' that Aladdin will be told to turn right, while 'S' means the wizard sleeps that day.
An old prophecy says that after K changes in direction (in steps 1 and/or 2) Aladdin will find the Pear.
Write a program that calculates how many days the search will last, according to the ancient prophecy.
He has decided to find the Golden Pear, an extremely valuable legendary artifact that no one has been able to find.
The desert Aladdin is searching is can be modeled as an N×N grid of cells. Rows and columns are numbered 1 through N top to bottom and left to right. Some of the cells in the desert contain wizards that help Aladdin's quest in an unusual way.
Aladdin starts his quest in the top left corner of the desert on a Monday facing right. His movement involves repeating these steps:
1. If the current cell contains a wizard that is awake, then Aladdin turns 90 degrees left or right, depending on what the wizard says.
2. If moving forward would take Aladdin out of desert, he turns 180 degrees.
3. Aladdin moves forward one cell and it takes him exactly one day.
For each wizard we know his location and his activity schedule for each day of the week. The schedule is a string of exactly seven letters 'L', 'R' or 'S', each character telling us what the wizard does on one day of the week (starting with Monday). The letter 'L' means that Aladdin will be told to turn left, 'R' that Aladdin will be told to turn right, while 'S' means the wizard sleeps that day.
An old prophecy says that after K changes in direction (in steps 1 and/or 2) Aladdin will find the Pear.
Write a program that calculates how many days the search will last, according to the ancient prophecy.
输入格式
The first line contains two integers N and K (2 ≤ N ≤ 200, 1 ≤ K ≤ 1 000 000 000), the size of the desert and the number of direction changes in the prophecy.
The second line contains an integer M (0 ≤ M ≤ 10000), the number of wizards.
Each of the following M lines contains two integers R and C (1 ≤ R, C ≤ N), and a string of seven letters 'L', 'R' or 'S'. The numbers represent the row and column where the wizard is located, while the string is his schedule.
No two wizards will share the same cell, nor will there be a wizard in cell (1, 1).
The second line contains an integer M (0 ≤ M ≤ 10000), the number of wizards.
Each of the following M lines contains two integers R and C (1 ≤ R, C ≤ N), and a string of seven letters 'L', 'R' or 'S'. The numbers represent the row and column where the wizard is located, while the string is his schedule.
No two wizards will share the same cell, nor will there be a wizard in cell (1, 1).
输出格式
Output the length of the search in days.
输入输出样例
输入 #1
3 1 0
输出 #1
2
输入 #2
5 2 2 1 3 RRSRRRR 1 5 RRRRLRR
输出 #2
4
输入 #3
5 5 3 1 3 SSRSSSS 3 3 SSSLSSS 4 3 SSRSSLS
输出 #3
10
In test cases worth 50% of points, K will be at most 1000.
In the first example, Aladdin moves twice, reaching the edge of the desert. He then turns 180 degrees
and finds the Pear.
In the second example, Aladdin reaches the first wizard on the third day, but the wizard is sleeping so
Aladdin continues in the same direction. After two more days he reaches the other wizard who tells
him to turn left. Aladdin does so, reaches the edge of the desert, turns back and finds the pair.
In the first example, Aladdin moves twice, reaching the edge of the desert. He then turns 180 degrees
and finds the Pear.
In the second example, Aladdin reaches the first wizard on the third day, but the wizard is sleeping so
Aladdin continues in the same direction. After two more days he reaches the other wizard who tells
him to turn left. Aladdin does so, reaches the edge of the desert, turns back and finds the pair.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted