http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82987#problem/H
题目
题目
#include<iostream>
#include<vector>
#include<cstring>
#include<cstdio>
#define Maxn 2000010
using namespace std;
char map[1010][1010];
bool Swap[1010][1010];
bool space[1010][1010];
const int ox = 505;
const int oy = 505;
void change (int diff) {
for (int x = ox-diff; x <= ox+diff; x++) {
for (int y = oy+diff; y >= oy-diff; y--) {
Swap[oy*2-y][x] = space[x][y];
}
}
for (int x = ox-diff; x <= ox+diff; x++) {
for (int y = oy+diff; y >= oy-diff; y--) {
space[x][y] = Swap[x][y];
}
}
}
int main () {
int t;
while (cin >> t, t) {
int diff = t/2;
for (int x = ox-diff; x <= ox+diff; x++) {
for (int y = oy+diff; y >= oy-diff; y--) {
if ((x == ox || y == oy) && t%2 == 0)
continue;
char tmp;
cin >> tmp;
if (tmp == 'O')
space[x][y] = 1;
else
space[x][y] = 0;
}
}
for (int x = ox-diff; x <= ox+diff; x++) {
for (int y = oy+diff; y >= oy-diff; y--) {
if ((x == ox || y == oy) && t%2 == 0)
continue;
cin >> map[x][y];
}
}
int times = 4;
while (times--) {
for (int x = ox-diff; x <= ox+diff; x++) {
for (int y = oy+diff; y >= oy-diff; y--) {
if ((x == ox || y == oy) && t%2 == 0)
continue;
if (space[x][y])
cout << map[x][y];
}
}
if (times)
change(diff);
}
cout << endl;
}
return 0;
}
利用swap数组作为辅助空间
把505这一行和505这一列虚拟成了坐标轴
采用了x=-y
y=x的坐标转化方式
因为这个图中的坐标不是从零开始的,所以要做一下处理,也就是x=oy*2-y
y=x的做法
把505这一行和505这一列虚拟成了坐标轴
采用了x=-y
y=x的坐标转化方式
因为这个图中的坐标不是从零开始的,所以要做一下处理,也就是x=oy*2-y
y=x的做法