模拟->YY POJ 2339 Rock, Scissors, Paper
2013-10-13 22:04
435 查看
Rock, Scissors, PaperTime Limit:5000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uSubmit Status Practice POJ2339DescriptionBart's sister Lisa has created a new civilization on a two-dimensional grid. At the outset each grid location may be occupied by one of three life forms: Rocks, Scissors, or Papers. Each day, differing life forms occupying horizontallyor vertically adjacent grid locations wage war. In each war, Rocks always defeat Scissors, Scissors always defeat Papers, and Papers always defeat Rocks. At the end of the day, the victor expands its territory to include the loser's grid position. The loservacates the position.Your job is to determine the territory occupied by each life form after n days.InputThe first line of input contains t, the number of test cases. Each test case begins with three integers not greater than 100: r and c, the number of rows and columns in the grid, and n. The grid is represented by the r lines thatfollow, each with c characters. Each character in the grid is R, S, or P, indicating that it is occupied by Rocks, Scissors, or Papers respectively.OutputFor each test case, print the grid as it appears at the end of the nth day. Leave an empty line between the output for successive test cases.Sample Input
2 3 3 1 RRR RSR RRR 3 4 2 RSPR SPRS PRSPSample Output
RRR RRR RRR RRRS RRSP RSPR
#include <iostream>#include <stack>#include <string>#include <string.h>#include <queue>#include <cmath>#include <map>#include <cstdio>using namespace std;char mapto[101][101];char maptoo[101][101];int main(){int t, r, c, n;cin >> t;while (cin >> r >> c >> n){for (int i = 0; i < r; i++){for (int j = 0; j < c; j++){cin >> mapto[i][j];maptoo[i][j] = mapto[i][j];}}if (n == 0){for (int i = 0; i < r; i++){for (int j = 0; j < c; i++){cout << mapto[i][j];}cout << endl;}}else{for (int k = 0; k < n; k++){for (int i = 0; i < r; i++){for (int j = 0; j < c; j++){if (mapto[i][j] == 'S'){if (i + 1 < r){if (mapto[i + 1][j] == 'R'){maptoo[i][j] = 'R';}if (mapto[i + 1][j] == 'P'){maptoo[i + 1][j] = 'S';}}if (i - 1 >= 0){if (mapto[i - 1][j] == 'R'){maptoo[i][j] = 'R';}if (mapto[i - 1][j] == 'P'){maptoo[i - 1][j] = 'S';}}if (j + 1 < c){if (mapto[i][j + 1] == 'R'){maptoo[i][j] = 'R';}if (mapto[i][j + 1] == 'P'){maptoo[i][j + 1] = 'S';}}if (j - 1 >= 0){if (mapto[i][j - 1] == 'R'){maptoo[i][j] = 'R';}if (mapto[i][j - 1] == 'P'){maptoo[i][j - 1] = 'S';}}}else if (mapto[i][j] == 'R'){if (i + 1 < r){if (mapto[i + 1][j] == 'S'){maptoo[i + 1][j] = 'R';}if (mapto[i + 1][j] == 'P'){maptoo[i][j] = 'P';}}if (i - 1 >= 0){if (mapto[i - 1][j] == 'S'){maptoo[i - 1][j] = 'R';}if (mapto[i - 1][j] == 'P'){maptoo[i][j] = 'P';}}if (j + 1 < c){if (mapto[i][j + 1] == 'S'){maptoo[i][j + 1] = 'R';}if (mapto[i][j + 1] == 'P'){maptoo[i][j] = 'P';}}if (j - 1 >= 0){if (mapto[i][j - 1] == 'S'){maptoo[i][j - 1] = 'R';}if (mapto[i][j - 1] == 'P'){maptoo[i][j] = 'P';}}}else{if (i + 1 < r){if (mapto[i + 1][j] == 'S'){maptoo[i][j] = 'S';}if (mapto[i + 1][j] == 'R'){maptoo[i + 1][j] = 'P';}}if (i - 1 >= 0){if (mapto[i - 1][j] == 'S'){maptoo[i][j] = 'S';}if (mapto[i - 1][j] == 'R'){maptoo[i - 1][j] = 'P';}}if (j + 1 < c){if (mapto[i][j + 1] == 'S'){maptoo[i][j] = 'S';}if (mapto[i][j + 1] == 'R'){maptoo[i][j + 1] = 'P';}}if (j - 1 >= 0){if (mapto[i][j - 1] == 'S'){maptoo[i][j] = 'S';}if (mapto[i][j - 1] == 'R'){maptoo[i][j - 1] = 'P';}}}}}for (int i = 0; i < r; i++){for (int j = 0; j < c; j++){mapto[i][j] = maptoo[i][j];}}}for (int i = 0; i < r; i++){for (int j = 0; j < c; j++){cout << mapto[i][j];}cout << endl;}cout << endl;}}return 0;}
思路:剪头石子布,按个模拟,顺序征服。[/code]
相关文章推荐
- POJ 2339 Rock, Scissors, Paper(模拟)
- POJ 2339 Rock, Scissors, Paper 模拟
- poj 2339 Rock, Scissors, Paper 模拟
- POJ 2339 Rock, Scissors, Paper
- POJ - 2339 Rock, Scissors, Paper
- poj 2339 Rock, Scissors, Paper
- POJ-2339-Rock, Scissors, Paper
- POJ 2339 Rock, Scissors, Paper 笔记
- 模拟->YY POJ 1028 Web Navigation
- 模拟->YY POJ 2612 Mine Sweeper
- poj 2339 Rock, Scissors, Paper
- poj 2339 Rock, Scissors, Paper
- poj 2339 Rock, Scissors, Paper
- poj 2339 Rock, Scissors, Paper
- 模拟->YY POJ 1786
- Rock, Scissors, Paper(模拟)
- 数学-> YY POJ 1338
- YY->POJ 1328
- POJ 2654 Rock-Paper-Scissors Tournament(水~)
- POJ 3488 & HDU 1915 Arne Saknussemm(模拟)