poj 2339 Rock, Scissors, Paper
2011-11-22 09:59
369 查看
Rock, Scissors, Paper
Description
Bart'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 horizontally or 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 loser vacates the position.
Your job is to determine the territory occupied by each life form after n days.
Input
The 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 that follow, 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.
Output
For 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
Sample Output
Time Limit: 5000MS | Memory Limit: 65536K | |
Total Submissions: 3106 | Accepted: 1838 |
Bart'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 horizontally or 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 loser vacates the position.
Your job is to determine the territory occupied by each life form after n days.
Input
The 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 that follow, 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.
Output
For 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 PRSP
Sample Output
RRR RRR RRR RRRS RRSP RSPR
#include<iostream> using namespace std; int judge(char a,char b) { if(a==b) return 0; if(a=='P'&&b=='S' || a=='R'&&b=='P' || a=='S'&& b=='R') return -1; return 1; } int main() { char grid[105][105]; char res[105][105]; int cases; int r,c,n; // freopen("E:\\c++\\oj\\t.txt","rt",stdin); cin>>cases; while(cases--) { cin>>r>>c>>n; for(int i=0;i<r;i++) { cin>>grid[i]; } for(int i=0;i<n;i++) { for(int m=0;m<r;m++) { for(int n=0;n<c;n++) { if(m-1>=0) { if(judge(grid[m] ,grid[m-1] )==-1) { res[m] =grid[m-1] ; continue; } } if(n-1>=0) { if(judge(grid[m] ,grid[m][n-1])==-1) { res[m] =grid[m][n-1]; continue; } } if(m+1<r) { if(judge(grid[m] ,grid[m+1] )==-1) { res[m] =grid[m+1] ; continue; } } if(n+1<c) { if(judge(grid[m] ,grid[m][n+1])==-1) { res[m] =grid[m][n+1]; continue; } } res[m] =grid[m] ; } } for(int i=0;i<r;i++) { for(int j=0;j<c;j++) { grid[i][j]=res[i][j]; } } } for(int i=0;i<r;i++) { for(int j=0;j<c;j++) { cout<<res[i][j]; } cout<<endl; } cout<<endl; } return 0; }
相关文章推荐
- 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 2339 Rock, Scissors, Paper
- POJ - 2339 Rock, Scissors, Paper
- poj 2339 Rock, Scissors, Paper
- poj 2339 Rock, Scissors, Paper
- POJ 2654 Rock-Paper-Scissors Tournament(水~)
- Mini-project # 1 - Rock-paper-scissors-___An Introduction to Interactive Programming in Python"RICE"
- 省赛热身赛之――Yet Another Story of Rock-paper-scissors
- 【水状压】#45 A. Rock-paper-scissors
- poj 3917 Rock, Paper, Scissors
- Mini-project # 1 - Rock-paper-scissors-___An Introduction to Interactive Programming in Python"RICE"
- HDU2164:Rock, Paper, or Scissors?
- hdu——Rock, Paper, Scissors