POJ - 2339 Rock, Scissors, Paper
初看题目时就发了个错误,我因为没有耐心看题而不了解题目本身的意思,找不到做题的突破口,即使看了一些题解,还是没有想到方法。
后来在去问安叔,安叔一语道破天机,问我有没有搞清题目的意思,我才恍然大悟,做题当然要先搞懂题目意思,不然做什么题呢!以后一定要再三注意!而且要把每一个细节都注意到!
POJ - 2339 Rock, Scissors, Paper
Time Limit: 5000MS |
Memory Limit: 65536KB |
64bit IO Format: %I64d & %I64u |
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
2
3 3 1
RRR
RSR
RRR
3 4 2
RSPR
SPRS
PRSP
Sample Output
RRR
RRR
RRR
RRRS
RRSP
RSPR
Source
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
char toda[][];
char tomo[][];
int main()
{
int t = , r = , c = , n = , i = , j = ;
scanf("%d", &t);
while(t--) {
scanf("%d%d%d", &r, &c, &n);
for(i = ; i < r; i++) {
scanf("%s", toda[i]);
}
for(i = ; i < r; i++) {
for(j = ; j < c; j++) {
tomo[i][j] = toda[i][j];
}
}
while(n--) {
for(i = ; i < r; i++) {
for(j = ; j < c; j++) {
if(toda[i][j] == 'R') {
if(j+ < c && toda[i][j+] == 'S')
tomo[i][j+] = 'R';
if(i- >= && toda[i-][j] == 'S')
tomo[i-][j] = 'R';
if(j- >= && toda[i][j-] == 'S')
tomo[i][j-] = 'R';
if(i+ < r && toda[i+][j] == 'S')
tomo[i+][j] = 'R';
}
else if(toda[i][j] == 'S') {
if(j+ < c && toda[i][j+] == 'P')
tomo[i][j+] = 'S';
if(i- >= && toda[i-][j] == 'P')
tomo[i-][j] = 'S';
if(j- >= && toda[i][j-] == 'P')
tomo[i][j-] = 'S';
if(i+ < r && toda[i+][j] == 'P')
tomo[i+][j] = 'S';
}
else {
if(j+ < c && toda[i][j+] == 'R')
tomo[i][j+] = 'P';
if(i- >= && toda[i-][j] == 'R')
tomo[i-][j] = 'P';
if(j- >= && toda[i][j-] == 'R')
tomo[i][j-] = 'P';
if(i+ < r && toda[i+][j] == 'R')
tomo[i+][j] = 'P';
}
}
}
for(i = ; i < r; i++) {
for(j = ; j < c; j++) {
toda[i][j] = tomo[i][j];
}
}
}
for(i = ; i < r; i++) {
for(j = ; j < c; j++) {
printf("%c", toda[i][j]);
}
printf("\n");
}
if(n) printf("\n");
}
return ;
}
POJ - 2339 Rock, Scissors, Paper的更多相关文章
- POJ 2339
#include <iostream> #include <algorithm> #define MAXN 205 using namespace std; char _m[M ...
- POJ 题目分类(转载)
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...
- (转)POJ题目分类
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
- poj分类
初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. ( ...
- poj 题目分类(1)
poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...
- POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)
本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...
- POJ题目分类(转)
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- POJ题目(转)
http://www.cnblogs.com/kuangbin/archive/2011/07/29/2120667.html 初期:一.基本算法: (1)枚举. (poj1753,poj29 ...
随机推荐
- Tom and paper
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5224 题意: 给出矩形的面积,求出最小的周长. 样例: Sample Input 3 2 7 12 ...
- [LintCode] Valid Palindrome 验证回文字符串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- ado.net 修改,查询
修改: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syst ...
- js封装
方法一: function Tetrio(singleW){ if(singleW == undefined){ singleW = 18; } this.x = 0; this.y = 0;} Te ...
- 用外部表的方式查询当天数据库alert日志文件
1环境准备 2查询ORA-开头的错误
- Linux常用命令(持续更新)
lsb_release -a 查看linux操作系统信息 getconf LONG_BIT 查看linux操作系统位数 useradd [-g groupname] username 创建用户,并指定 ...
- boostrap折叠,jquery ui accordion同时打开多个标签
http://caibaojian.com/bootstrap/javascript.html http://www.w3cschool.cc/jqueryui/example-accordion.h ...
- 5_STL设计理念_迭代器
他山之石,可以攻玉. http://blog.csdn.net/jxh_123/article/details/30793397?utm_source=tuicool&utm_medium=r ...
- HDU1004之总是wa的细节问题
#include <stdio.h> #include <string.h> int main() { ][]; int n, i, k, j, max, max_i; ){ ...
- 四则运算之C++实现篇
对四则运算的一些要求如下: 1.题目避免重复:2.可定制(数量/打印方式):3.可以控制下列参数: 是否有乘除法.数值范围.加减有无负数.除法有无余数.否支持分数 (真分数, 假分数, …): 一 ...