poj_2339
参考:https://blog.csdn.net/yzl_rex/article/details/7600906
https://blog.csdn.net/acm_JL/article/details/50200355
https://blog.csdn.net/qq_35040828/article/details/71123521
https://zhidao.baidu.com/question/49762862.html
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N=;
char old[N][N],news[N][N];//old存旧数组,news存新数组
int dir[][]={{-,,,},{,,,-}};//周围四个格
int r,l,n;
int lawful(int x,int y)//判断是否超出边界
{
if (x>=&&x<r&&y>=&&y<l)
{
return ;
}
else
{
return ;
}
}
char change(int x,int y)//依据规则改变
{
for (int i=;i<;i++)
{
int xx=x+dir[][i];
int yy=y+dir[][i];
if (lawful(xx,yy))
{
if (old[xx][yy]=='R'&&old[x][y]=='S')
{
return 'R';
}
else if (old[xx][yy]=='S'&&old[x][y]=='P')
{
return 'S';
}
else if (old[xx][yy]=='P'&&old[x][y]=='R')
{
return 'P';
}
}
}
return old[x][y];
}
int main()
{
int t;
// freopen("bin.txt","r",stdin);
while (cin>>t)
{
while (t--)
{
cin>>r>>l>>n;
memset(old,,sizeof(old));
memset(news,,sizeof(news));
for (int i=;i<r;i++)
{
for (int j=;j<l;j++)
{
cin>>old[i][j];
}
}
for (int i=;i<n;i++)
{
for (int j=;j<r;j++)
{
for (int k=;k<l;k++)
{
news[j][k]=change(j,k);//更新news
}
}
memcpy(old,news,sizeof(news));
}
for (int i=;i<r;i++)
{
for (int j=;j<l;j++)
{
cout<<old[i][j];
}
cout<<endl;
}
cout<<endl;
}
} return ;
}
poj_2339的更多相关文章
随机推荐
- 1.GlusterFS 初识
一. GlusterFS 初始 1.1 分布式文件系统出现 计算机通过文件系统管理.存储数据,而现在数据信息爆炸的时代中人们可以获取的数据成指数倍的增长,单纯通过增加硬盘个数来扩展计算机文件系统的存储 ...
- python中的 if __name__ == “__main__”: 有什么用
https://stackoverflow.com/questions/419163/what-does-if-name-main-do# 问题: What does if name == " ...
- diskpart分区
分区知识充电: 主分区:主分区,也称为主磁盘分区,和拓展分区.逻辑分区一样,是一种分区类型.主分区中不能再划分其他类型的分区,因此每个主分区都相当于一个逻辑磁(在这一点上主分区和逻辑分区很相似,但主分 ...
- May 21st 2017 Week 21st Sunday
The smallest deed is better than the greatest intention. 最微小的行动胜过最伟大的打算. Several years ago, just aft ...
- SqlSugar之SqlQueryDynamic返回值处理
现在有个需求,有一张表每个月表名都会变的,但结构是一样的,我们不能再用类映射来完成的,我不能每个月都去手动添加,我们只能使用sql语句来完成这个需求.为了方便我这边选择的是SqlQueryDynami ...
- C++/C 内存大小
#include <stdio.h> struct test1{ char a1; int a2; double a3;}; struct test2{ char ...
- 关于object类的两个重要方法以及为什么重写equals一定要重写hashcode()
toString()----------------------输出对象的地址 重写后输出对象的值对象.equals(对象)---------------比较两个对象的内存地址 可以被重写,重写后比较 ...
- 关于ProjectServer定制化项目中心页面
ProjectServer界面很多客户接受不了,随便用户可以根据自己需要展示页面,但大多数国内用户喜欢确定的样式,我就是要这样的页面,不要个人定制. 那只有自己再做一个项目中心的webpart嵌入,对 ...
- 简析--UUID
内容转载自:http://www.cnblogs.com/java-class/p/4727698.html 阅读目录 1.UUID简介 2.UUID组成 3.UUID实战演练 1.UUID 简介 U ...
- jquery mobile 移动web(4)
下拉菜单: 设置label 元素的for 属性为 select label 元素的文本内容作为选项的名称 定义div元素并设置data-role 属性值为 fieldcontain. <div ...