poj_2339
2024-08-23 09:58:47
参考: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 ;
}
最新文章
- 适配iOS 10以及Xcode 8(转载)
- 【原】移动web页面使用字体的思考
- How To Handle a Loss of Confidence in Yourself
- 通过profiler对unity进行针对性优化
- select接收后台返回值的解决方案
- 【JQuery】jQuery.inArray 确定第一个参数在数组中的位置
- C#写文本日志帮助类(支持多线程)
- Java学习-011-创建文件实例及源代码
- 自我提升mysql
- kafka的一些名词
- Windows 窗体的.Net 框架绘图技术
- jQuery移除指定元素后的所有元素
- ubuntu15.10下sublime text3 无法输入中文解决办法
- Canvas rontate(旋转) 使用误区
- Linux进程的状态转换图
- hdu2108 Shape of HDU 极角排序判断多边形
- Emmet for Dreamweaver:HTML/CSS代码快速编写神器
- codeforces960G. Bandit Blues
- mysql Table &#39;user&#39; is marked as crashed and should be repaired
- python3-元类
热门文章
- Selenium2学习(九)-- 多窗口,句柄(handle)
- Linux文件压缩和解压缩命令
- MySQL的基础(优化)3
- 笨办法学Python(四十)
- GitLab 数据自动备份
- March 16 2017 Week 11 Thursday
- python3乱码问题:接口返回数据中文乱码问题解决
- 第一次在stack overflow回答问题
- python manage.py startapp app 时候报错No module named _sqlite3
- C++11之 Move semantics(移动语义)(转)