📄 2169.cpp
字号:
/* This Code is Submitted by wywcgs for Problem 2169 on 2006-03-18 at 19:24:46 */
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const char INTRO[][8] = { "id", "rot", "sym", "bhsym", "bvsym", "div", "mix",
"id-", "rot-", "sym-", "bhsym-", "bvsym-", "div-", "mix-", };
const int L = 32;
const int SIZE = 1024;
int n, mid, in, io[L];
void next(int&, int&);
void rot(int&, int&, bool);
void div(int&, int&, bool);
void mix(int&, int&, bool);
int main()
{
bool vst[SIZE][SIZE];
int i, j;
while(scanf("%d", &n) != EOF) {
memset(vst, false, sizeof(vst)); mid = n >> 1;
for(in = 0; true; in++) {
char intro[8]; scanf("%s", intro);
for(io[in] = 0; strcmp(intro, INTRO[io[in]]); io[in]++) ;
if(getchar() == '\n') break;
}
int step = 1;
for(i = 0; i < n; i++)
for(j = 0; j < n; j++) {
if(vst[i][j]) continue;
int x = i, y = j, m;
for(m = 0; !vst[x][y]; m++) { vst[x][y] = true; next(x, y); }
step *= m / __gcd(step, m);
}
printf("%d\n", step);
}
return 0;
}
void next(int& x, int& y)
{
int i;
for(i = in; i >= 0; i--) {
switch(io[i]) {
case 1: case 8: rot(x, y, io[i]>7); break;
case 2: case 9: y = n-1-y; break;
case 3: case 10: if(x >= mid) y = n-1-y; break;
case 4: case 11: if(x >= mid) x = n-1-x+mid; break;
case 5: case 12: div(x, y, io[i]>7); break;
case 6: case 13: mix(x, y, io[i]>7); break;
}
}
}
void rot(int& x, int& y, bool anti)
{
int cx, cy;
if(anti) { cx = y; cy = n-1-x; }
else { cx = n-1-y; cy = x; }
x = cx; y = cy;
}
void div(int& x, int& y, bool anti)
{
if(anti) x = x/mid+x%mid*2;
else x = mid*(x&1)+(x>>1);
}
void mix(int& x, int& y, bool anti)
{
int cx, cy;
if(anti) { cx = (x&(SIZE-2))+(y&1); cy = (y>>1)+mid*(x&1); }
else { cx = (x&(SIZE-2))+y/mid; cy = y%mid*2+(x&1); }
x = cx; y = cy;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -