旋转过程的下标变化,画个2x2的表格,模拟就可以出来了
#include <string> #include<iostream> #include<map> #include<memory.h> #include<vector> #include<algorithm> namespace cc { using std::cout; using std::endl; using std::cin; using std::map; using std::vector; using std::string; using std::sort; constexpr int N = 51; map<string, int> status; int board[N][N]; int n; string toString(int b[][N]) { string str = ""; for (int i=1;i<=n;i++) { for (int j=1;j<=n;j++) { str += std::to_string(b[i][j]); } } return str; } string xuanzhuan(int i) { int temp[N][N]; if (i == 0) { //顺时针90度 for (int i = 1, k = n; i <= n; i++, k--) for (int j = 1; j <= n; j++) temp[j][k] = board[i][j]; return toString(temp); } else if (i==1) { for (int i = 1, k = n; i <= n; i++, k--) for (int j = 1; j <= n; j++) temp[j][k] = board[i][j]; // 180 int temp2[N][N]; for (int i = 1, k = n; i <= n; i++, k--) for (int j = 1; j <= n; j++) temp2[j][k] = temp[i][j]; return toString(temp2); } else if (i==2) { for (int i = 1; i <= n; i++)//逆时针90度 for (int j = 1, k = n; j <= n; j++, k--) temp[k][i] = board[i][j]; return toString(temp); } } void solve() { while (cin>>n&&n) { memset(board,0,sizeof(board)); status.clear(); int r, c; char op; int ok = 0; int play = 1; int step = 0; for (int i=1;i<=2*n;i++) { cin >> r >> c >> op; if (op=='-') { //nazou board[r][c] = 0; } else { board[r][c] = 1; } if(ok==0) { step=i; play = i; string str = ""; str = xuanzhuan(0); if (ok==0&&status[str] == 1) { ok = 1; } str = xuanzhuan(1); if (ok == 0 && status[str] == 1) { ok = 1; } str = xuanzhuan(2); if (ok == 0 && status[str] == 1) { ok = 1; } str = toString(board); if (ok == 0 && status[str] == 1) { ok = 1; } status[str] = 1; } } if (ok == 0) { cout << "Draw" << endl; } else { cout << "Player " << (play % 2+1) << " wins on move " << step << endl; } } } }; int main() { #ifndef ONLINE_JUDGE freopen("d://1.text", "r", stdin); #endif // !ONLINE_JUDGE cc::solve(); return 0; }