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 ...
随机推荐
- Linux_几个符号命令
一.管道符号 | (将前面命令的输出结果传给后面的命令) [eRrsr@hadoop09-linux ~]$ cat /etc/passwd | grep "^root" root ...
- POJ 1016 模拟字符串
Numbers That Count Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20396 Accepted: 68 ...
- webapp 公共样式
html{ font-size: 62.5%;}@media only screen and (min-width: 481px) { html { font-size:94%!important } ...
- JAVA6开发WebService (二)——JAX-WS例子
转载自http://wuhongyu.iteye.com/blog/807836 上一篇写了个最简单的小例子,只是为了说明JAVA6开发Web Service很方便,这一篇稍微深入一点,写个稍微有点代 ...
- centos install zookeeper cluster
1.apache官方下载, 2.新版本需要jdk环境,然后配置好jdk环境 3.解压zookeeper,进入解压后的conf,新建zoo.cfg (删掉自带的cfg)内容如下 tickTime=200 ...
- 需要注意学习.net过程的要点
基础部分 C# 基础语法 OOP的概念,面向对象的理解 继承 封装 多态 ASP.NET MVC (Web Form 用的越来越少,如果你不熟悉,可以不看) JavaScript 基础语法 如何在HT ...
- iOS 如何通过CocoaPods添加第三方框架
一 先安装Ruby环境: http://ruby-china.org/wiki/install_ruby_guide 在安装的时候,若是出现: 1.You don't have write perm ...
- IOS第二天多线程-01-延时执行
**********延时执行 #import "HMViewController.h" @interface HMViewController () @end @implement ...
- P1514 引水入城
概述 首先,这是一道好题,这道题既考查了图论的dfs知识,又考察了区间贪心问题中很典型的区间覆盖问题,着实是一道好题. 大概思路说明 我们观察到,只有第一行可以放水库,而第一行在哪里放水库的结果就是直 ...
- 【翻译】How To Tango With Django 1.5.4 第五章
5数据模型和数据库 一个模型就是一个描述你数据表的python对象.不用再通过SQL来操作数据库,而是使用python对象来操作数据库. 5.1rango要求 ...一个目录下面有多个下面 ...一个 ...