poj 2339 Rock, Scissors, Paper
来源:互联网 发布:紧急域名网页升级访问 编辑:程序博客网 时间:2024/06/05 05:49
在一个矩阵里面玩 石头剪刀纸,规则大家都懂的,每次如果上下左右的被打败,则其将被取代为胜利者的标志,这里不能用原图来进行处理,所以需要建立个参考矩阵,每次都用参考矩阵来进行判断,然后更改map矩阵的情况,好像这样时间复杂度确实不小,500ms水过。
#include<cstdio>#include<cstring>#include<iostream>using namespace std;const int N = 105;int row, col, n;char map[N][N];char refer[N][N];int di[4][2] = {0,1,1,0,-1,0,0,-1};bool judge(int x,int y){ if(x>0&&x<=row&&y>0&&y<=col) return true; return false;}void print(){ for(int i=1; i<=row; ++i) { for(int j=1; j<=col; ++j) printf("%c",map[i][j]); putchar(10); } putchar(10);}void ini(){ for(int i=1; i<=row; ++i) for(int j=1; j<=col; ++j) refer[i][j] = map[i][j];}int main(void){ int ncase; scanf("%d",&ncase); while(ncase--) { scanf("%d%d%d",&row,&col,&n); for(int i=1; i<=row; ++i) { scanf("%s",map[i]+1); } while(n--) { ini(); for(int i = 1; i<=row; ++i) for(int j=1; j<=col; ++j) { if(refer[i][j] == 'R') { int a,b; for(int k=0; k<4; ++k) { a = i + di[k][0]; b = j + di[k][1]; if(judge(a,b)&&refer[a][b]=='S') map[a][b] = 'R'; } } else if(refer[i][j] == 'S') { int a,b; for(int k=0; k<4; ++k) { a = i + di[k][0]; b = j + di[k][1]; if(judge(a,b)&&refer[a][b]=='P') map[a][b] = 'S'; } } else { int a,b; for(int k=0; k<4; ++k) { a = i + di[k][0]; b = j + di[k][1]; if(judge(a,b)&&refer[a][b]=='R') map[a][b] = 'P'; } } } } print(); } return 0;}
- poj 2339 Rock, Scissors, Paper
- POJ 2339 Rock, Scissors, Paper
- POJ-2339-Rock, Scissors, Paper
- poj 2339 Rock, Scissors, Paper
- POJ - 2339 Rock, Scissors, Paper
- poj 2339 Rock, Scissors, Paper
- poj 2339 Rock, Scissors, Paper
- poj 2339 Rock, Scissors, Paper 模拟
- 模拟->YY POJ 2339 Rock, Scissors, Paper
- POJ 2339 Rock, Scissors, Paper(模拟)
- POJ 2339 Rock, Scissors, Paper 模拟
- POJ 2339 Rock, Scissors, Paper 笔记
- poj 3917 Rock, Paper, Scissors
- poj 2654 Rock-Paper-Scissors Tournament
- POJ-2654-Rock-Paper-Scissors Tournament
- POJ 3917 Rock, Paper, Scissors G++
- Rock-Paper-Scissors
- 【poj2339】Rock, Scissors, Paper
- 批量上传+类似百度文库在线预览功能
- Boost - 序列化 (Serialization)
- java的HashMap与ConcurrentHashMap
- 安卓自动化测试工具MonkeyRunner之使用ID
- Invalid layout param in a LinearLayout: layout_toLeftOf
- poj 2339 Rock, Scissors, Paper
- 论文笔记
- 解决Mac机下javac乱码问题
- 一个有趣的抛硬币问题
- GetSystemTime和GetLocalTime
- 2011-09-24百度笔试题(技术研发)
- 实现任意图片(高度不确定)垂直居中的三种方法
- Jquery-1.8.x 与Jquery-1.9.x, Jquery-1.10.x对checkbox操作方法的支持
- 北汽威旺M20 向时尚进军