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的更多相关文章
随机推荐
- /etc/hosts.allow和/etc/hosts.deny详解
今天遇到一台服务器22端口正常,但是通过ssh连接的问题.排查了防火墙和端口问题,半天没有找出来原因,后来求助大神,终于明白了通过etc目录下hosts.deny和hosts.allow文件可以限制远 ...
- Eclipse集成Maven(手工安装Maven且手工集成到Eclipse)
1.操作环境 操作系统:win8 64位 IDE:Helios Eclipse 1.8 JDK:1.6 2.资源准备 2.1 maven安装包: apache-maven-3.2.5-bin.zip ...
- 安装OUD报错,unsupported classversion 51.0
查找,错误代码,在一篇博客中看到:补充:后经实例证明,在eclipse中进行开发的时候,build path 中JDK进行类库的编译(就是你使用类在不在这个JDK中),java compiler co ...
- js原型链继承及调用父类方法
方法1: var Parent= function () { }; Parent.prototype.process = function(){ alert('parent method'); }; ...
- Kubernetes Helm入门指南
什么是Helm?这可不是暗黑破坏神里装备的名称:头盔,而是Kubernetes的一个包管理工具,用来简化Kubernetes应用的部署和管理.我们Helm和Kubernetes的关系,我们可以理解成y ...
- 《编程导论(Java)·9.3.1回调·3》回调的实现
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/yqj2065/article/details/31441221 接<9.3.1Java回调 · ...
- 2018.11.17 Struts2框架入门
Struts2 框架学习 一.struts2是什么? (1)概念 (2)struts2使用优势 自动封装参数 参数校验 结果的处理(转发|重定向) 国际化 显示等待页面 表单的防止重复提交 (3)st ...
- Angular 引用库
<!doctype html> <html ng-app> <head> <script src="http://code.angularjs.or ...
- Dapper.net ORM
参考链接:https://github.com/StackExchange/dapper-dot-net Dapper - a simple object mapper for .Net Dapper ...
- grunt_beginner
前端集成解决方案:一套包含框架 和 工具,便于开发者快速构建美丽实用的web应用程序的工作流,同时 这套工作流必须是稳健强壮的. Yeman Bower web包管理器 框架.库.公共部分 Grunt ...