玩问题描述
Xiaoz最近对石头(R)、剪刀(S)、布(P)的游戏进行了创新已知有超邻 进行战斗,事
直且相邻格
每个格里面放着R、S、P中的一个字母 每天,不同格同它水平与方被赢的一方占领现在了,就占领对方的格,输了,就被对方占领每天战争结束后,,输的
确定经历1天游戏后,nxm的方格中的字母排列方式(o<n,m < 100)
样例
input
3 3 1
RRR
RSR
RRR
output
RRR
RRR
RRR
input
RSPR
SPRS
PRSP
output
RRRS
RRSP
RSPR
最近脑子有坑,哎哎哎,竟然刚看到题没思路,呜呜呜呜~
代码
#include <bits/stdc++.h>
using namespace std;
bool play(char a,char b)
{
if(a=='R'&&b=='P')
return false;
if(a=='P'&&b=='S')
return false;
if(a=='S'&&b=='R')
return false;
return true;
}
int main()
{
int n,m,t;
char map[110][110];
char tt[110][110];
cin>>n>>m>>t;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>map[i][j];
}
}
while(t--)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(i-1>=0&&!play(map[i][j],map[i-1][j]))
{
tt[i][j]=map[i-1][j];
}
else if(i+1<n&&!play(map[i][j],map[i+1][j]))
{
tt[i][j]=map[i+1][j];
}
else if(j-1>=0&&!play(map[i][j],map[i][j-1]))
{
tt[i][j]=map[i][j-1];
}
else if(j+1<m&&!play(map[i][j],map[i][j+1]))
{
tt[i][j]=map[i][j+1];
}
else
tt[i][j]=map[i][j];
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
map[i][j]=tt[i][j];
}
}
}
// for(int i=0;i<n;i++)
// {
// for(int j=0;j<m;j++)
// {
// cout<<map[i][j]<<" ";
// }
// cout<<endl;
// }
}