Chessboard
来源:互联网 发布:淘宝全屏热点代码 编辑:程序博客网 时间:2024/05/16 11:27
When the explorer Mahiro is venturing into the Mountains of Madness, he is caught by the Nyarlathotep, Nyarlathotep wants to play a dead game with Mahiro. Nyarlathotep has created an n×m chessboard, and the chessboard has two kinds of chess pieces--black and white. Nyarlathotep tells Mahiro an operation sequence including three operations:
1. add a white chess piece to position (x, y) (the input will be 1 1 x y)
2. add a black chess piece to position (x, y) (the input will be 1 2 x y)
2. swap the x1 row and x2 row (the input will be 2 x1 x2)
The length of the operation sequence will be q.
Notice: Originally, the chessboard is empty. If you add a chess piece to a position where it’s empty or there is already a chess piece, then this cell only contains the most recent chess piece.
Mahiro should find out the final chessboard as fast as possible, or he will be eaten by Nyarlathotep. Can you help him? Please look at the example for more details.
The first line contains three integers n, m and q (1<=n<=100, 1<=m<=10000, 1<=q<=100000) Then follow q lines are the operations. As for each operation, the format is described above. (1<=xi<=n,1<=yi<=m)
Output n lines each containing m characters. A ‘.’(period) for an empty cell, ‘b’ for a cell with black piece and ‘w’ for a cell with white piece.
样例一:2 2 21 1 1 12 1 2样例二:4 3 41 1 1 12 1 21 2 1 12 2 3
样例一:..w.样例二:b.....w.....
Problem Source: “火烈鸟杯”第八届中山大学程序设计新手赛网络预选赛
下面是一个acm队的代码(差距好大。。。。):
#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<iostream>#include<set>#include<string>#define rep(i,j,k) for (i=j;i<=k;i++)#define reps(i,j,k) for (i=j;i>=k;i--)#define mem(a,b) memset(a,b,sizeof(a))#define maxn 3100#define inf 0x3fffffffusing namespacestd;int map[110][11000],n,m,q,id[110];int main(){ int i,j,k; scanf("%d%d%d",&n,&m,&q); rep(i,1,n) rep(j,1,m)map[i][j]=0; rep(i,1,n)id[i]=i; rep(i,1,q){ int pos; scanf("%d",&pos); if (pos==1){ int col,x,y; scanf("%d%d%d",&col,&x,&y); map[id[x]][y]=col; } else{ int x,y; scanf("%d%d",&x,&y); swap(id[x],id[y]); } } rep(i,1,n){ rep(j,1,m)if (map[id[i]][j]==0)printf("."); elseif (map[id[i]][j]==1)printf("w"); elseprintf("b"); printf("\n"); } return0;}
下面是我的:
主要思路就是直接用了string,以及swap,压根没考虑优化,但是提交只告诉是WA,并非TLE,就没往优化方面想,还是自己太菜了。。。c艹
#include <iostream>#include <algorithm>#include <string>using namespacestd;string input[220];int main(){ int N,M,Q; scanf("%d%d%d",&N,&M,&Q); for (int n=1;n<=N;n++) for (int m=0;m<=M;m++)input[n][m]='.'; //若input[n][0]无填充值,后果? while (Q--) { int n,x,y; scanf("%d",&n); if (n==2) { scanf("%d%d",&x,&y); swap(input[x],input[y]); } elseif (n==1) { scanf("%d%d%d",&n,&x,&y); if (n==1) input[x][y]='w'; elseinput[x][y]='b'; } } for (int n=1;n<=N;n++) { for (int m=1;m<=M;m++)printf("%c",input[n][m]); printf("\n"); } return0;}
- Chessboard
- Chessboard
- Chessboard
- poj2446 Chessboard
- poj2446 Chessboard
- POJ2446 Chessboard
- poj2446 Chessboard
- POJ2446--Chessboard
- Incomplete Chessboard
- HDU5100-Chessboard
- hdu5100---Chessboard
- Chessboard(HDUOJ_5100)
- POJ2446 CHESSBOARD
- HDU5100 Chessboard
- Chessboard HDU
- chessboard create
- POJ_1657_Distance on Chessboard
- Chessboard------最大独立数
- 欢迎使用CSDN-markdown编辑器
- JVM相关知识总结
- 观察者模式浅谈篇(一)
- 简单Method.invoke
- nyoj 78
- Chessboard
- jdbc连接mysql
- RxJava操作符(一)Creating Observables
- android studio 快捷键
- maven(3)------maven构建web项目详细步骤
- bzoj4320 ShangHai2006 Homework
- Hadoop YARN 的工作流程简述
- (软件工程项目管理经验)git常用命令
- RxJava操作符(二)Transforming Observables