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 ...
随机推荐
- XML 参考:XML基础 XML 简介
XML 参考:XML基础 -- XML简介和用途 转:http://www.cnblogs.com/Dlonghow/archive/2009/01/22/1379799.html XML 参考:XM ...
- 一键搞定JavaEE应用,JRE+Tomcat+Mysql-JaveEE绿色运行环境JTM0.9版
本文转载自[http://www.blogjava.net/huliqing/archive/2009/01/09/247375.html] 这是一个集成了jre,tomcat,mysql的绿色运行环 ...
- [LintCode] Divide Two Integers 两数相除
Divide two integers without using multiplication, division and mod operator. If it is overflow, retu ...
- 读《深入php面向对象、模式与实践》有感(一)
什么样的代码需要改进?书中给出了四个标准(我个人比较认可这四个标准,实际开发中也的确时常遇到): 一.代码重复 用书中的原话讲:“如果你在写代码的时候,总是感觉似曾相识,很可能你的代码已经重复了”. ...
- jq遍历url判断是否为当前页面然后给导航上色
举例:我们希望在此页面点击“我的头像”从而加亮它的背景颜色,跟“我的爱好”的背景颜色一样. 之前: 之后: 我是这样实现的:通过判断当前url是否存在某字段,遍历字段所在的位置给加上相应的样式,我这么 ...
- get_magic_quotes_gpc()
php get_magic_quotes_gpc()函数:http://www.cnblogs.com/lsk/archive/2008/05/05/1184117.html 以及addslashes ...
- bzoj3991: [SDOI2015]寻宝游戏--DFS序+LCA+set动态维护
之前貌似在hdu还是poj上写过这道题. #include<stdio.h> #include<string.h> #include<algorithm> #inc ...
- php图片转为资源数据
$file='C:\Users\feng\Desktop\images\banner.png'; //图片路径 $type=getimagesize($file); ...
- time模块目录下自己建立一个名为log的文件夹
使用python调用ping命令,然后在日志中记录ping的结果,用来监测网络连通情况. 代码: [python]from time import *from subprocess import *w ...
- Ubuntu下编译第一个C程序的成功运行
1. 打开控制台:使用快捷键 Ctrl + Alt + T: 2. 安装gcc为C语言编译器,g++为C++ 语言编译器 sudo apt-get install g++. 3. 编辑好hello ...