QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#77740#5509. Kooky Tic-Tac-ToeXKErrorCompile Error//C++2.8kb2023-02-15 15:54:052023-02-15 15:54:06

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-15 15:54:06]
  • 评测
  • [2023-02-15 15:54:05]
  • 提交

answer

#include <bits/stdc++.h>

#define maxn 10

using namespace std;

int T;
int n, k;

char s[maxn][maxn];
int t[maxn][maxn];

int f[4][maxn][maxn];

bool check(int xi, int xj) {
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if ((xi == i && xj == j) || s[i][j] == '.') {
				f[0][i][j] = f[1][i][j] = f[2][i][j] = f[3][i][j] = 0;
			}
			else if (s[i][j] == 'x') {
				f[0][i][j] = (s[i][j - 1] == 'x' ? f[0][i][j - 1] : 0) + 1;
				f[1][i][j] = (s[i - 1][j - 1] == 'x' ? f[1][i - 1][j - 1] : 0) + 1;
				f[2][i][j] = (s[i - 1][j] == 'x' ? f[2][i - 1][j] : 0) + 1;
				f[3][i][j] = (s[i - 1][j + 1] == 'x' ? f[3][i - 1][j + 1] : 0) + 1;
			}
			else if (s[i][j] == 'o') {
				f[0][i][j] = (s[i][j - 1] == 'o' ? f[0][i][j - 1] : 0) + 1;
				f[1][i][j] = (s[i - 1][j - 1] == 'o' ? f[1][i - 1][j - 1] : 0) + 1;
				f[2][i][j] = (s[i - 1][j] == 'o' ? f[2][i - 1][j] : 0) + 1;
				f[3][i][j] = (s[i - 1][j + 1] == 'o' ? f[3][i - 1][j + 1] : 0) + 1;
			}
//			cout<<f[0][i][j]<<" ";
			if (f[0][i][j] >= k || f[1][i][j] >= k || f[2][i][j] >= k || f[3][i][j] >= k) return 1;
		}
//		cout<<endl;
	}
	return 0;
}

int tot1;
pair<int, int> g1[maxn];
int tot2;
pair<int, int> g2[maxn];

int main() {
	scanf("%d", &T);
	while (T--) {
		scanf("%d%d", &n, &k);
		for (int i = 0; i <= n + 1; i++) s[i][j] = 0;
		for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
		int cntx = 0, cnto = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if (s[i][j] == 'x') ++cntx;
				if (s[i][j] == 'o') ++cnto;
			}
		}
		if (abs(cntx - cnto) > 1) {
			puts("NIE");
			continue;
		}
		if (cntx + cnto != n * n && !check(0, 0)) {
			puts("NIE");
			continue;
		}
		int sx = 0, sy = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if (!check(i, j)) {
//					cout<<"F:"<<i<<" "<<j<<endl;
					if (s[i][j] == 'x' && abs(cntx - 1 - cnto) > 1) continue;
					if (s[i][j] == 'o' && abs(cntx - cnto + 1) > 1) continue;
					sx = i, sy = j;
					goto BK;
				}
			}
		}
		BK:;
		if (!sx) {
			puts("NIE");
			continue;
		}
		tot1 = tot2 = 0;
		char flg;
		if (cntx > cnto) flg = 'x';
		else if (cnto > cntx) flg = 'o';
		else flg = (s[sx][sy] == 'o' ? 'x' : 'o');
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) if (s[i][j] == flg && (i != sx || j != sy)) g1[++tot1] = {i, j};
		}
		if (flg == 'o') flg = 'x';
		else flg = 'o';
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) if (s[i][j] == flg && (i != sx || j != sy)) g2[++tot2] = {i, j};
		}
		puts("TAK");
		for (int i = 1; tot1 || tot2; i ^= 1) {
			if (i == 1) printf("%d %d\n", g1[tot1].first, g1[tot1].second), --tot1;
			else printf("%d %d\n", g2[tot2].first, g2[tot2].second), --tot2;
		}
		printf("%d %d\n", sx, sy);
	}
	return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:50:55: error: ‘j’ was not declared in this scope
   50 |                 for (int i = 0; i <= n + 1; i++) s[i][j] = 0;
      |                                                       ^
answer.code:47:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |         scanf("%d", &T);
      |         ~~~~~^~~~~~~~~~
answer.code:49:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   49 |                 scanf("%d%d", &n, &k);
      |                 ~~~~~^~~~~~~~~~~~~~~~
answer.code:51:51: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   51 |                 for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
      |                                              ~~~~~^~~~~~~~~~~~~~~~