参考: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. 【Leetcode】【Easy】Implement strStr()

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

  2. php入门到精通(复习笔记)

    第一章:php语言基础 1,标记风格: ①<?php echo “hello”;?> ②<script language="php">echo " ...

  3. June 08th 2017 Week 23rd Thursday

    Life is like a beautiful melody, only the lyrics are messed up. 生命是首美丽的曲子,虽然歌词有些纠结. Now that we get ...

  4. java--内存管理的几点小技巧

    今天看一本书,书上提到了内存泄露,后面也提到了内存管理的小技巧,在这里记下来,以免以后忘记. 1.尽量使用直接量.比如:String str = "I can play!";而不是 ...

  5. 问题 A: B 继承 圆到圆柱体

    题目描述 定义了Circle圆形类,在此基础上派生出Cylinder圆柱体类. Circle圆形类定义如下: class Circle { public: Circle(double r):radiu ...

  6. heidsql(mysql)安装教程和mysql修改密码

    简单介绍安装 官网下载:https://mariadb.org/download/ 直接下载(mariadb-10.3.9-winx64.msi):https://github.com/weibang ...

  7. hadoop二次排序

    import java.io.DataInput; import java.io.DataOutput; import java.io.File; import java.io.IOException ...

  8. watch、computed、methods的区别

    1. `computed`属性的结果会被缓存,除非依赖的响应式属性变化才会重新计算.主要当作属性来使用,要return出去一个值:2. `methods`方法表示一个具体的操作,主要书写业务逻辑:3. ...

  9. spring boot整合mybatis查询数据库返回Map字段为空不返回解决

    1.出现问题原因原因1:mybatis的配置即mapper返回映射配置. 原因2:jackson的配置即@ResponseBody序列化配置. 2.解决方式步骤1:解决原因1 mybatis: con ...

  10. 打包上传appsto错误 ERROR ITMS-90087: 和WARNING ITMS-90080: 问题

    第一个错误 (Hyphenate.framework可以看粗是环信问题) ERROR ITMS-90087: "Unsupported Architectures. The executab ...