为啥 cout 就 90 分但 printf 却 AC 了?
查看原帖
为啥 cout 就 90 分但 printf 却 AC 了?
502658
Ray662楼主2022/10/1 21:16

9090 分代码(cout)

#include <bits/stdc++.h>
#define int long long
#define _for(i, a, b)  for (int i = (a); i <= (b); i ++ )
using namespace std;
const int N = 50;
int T, n, S, ans, SG[N], P[N], vis[N * N];
signed main() {
	ios :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
	SG[0] = 0;
	_for (i, 1, 22) {
		_for (j, 0, i - 1)  _for (k, 0, j)  vis[SG[j] ^ SG[k]] = 1;
		int id = 0;
		while (vis[id])  id ++ ;
		SG[i] = id;
		memset(vis, 0, sizeof(vis));
	}
	cin >> T;
	while (T -- ) {
		cin >> n, S = 0, ans = 0;
		_for (i, 1, n) {
			cin >> P[i];
			if (P[i] & 1)  S ^= SG[n - i];
		}
		if (! S)  puts("-1 -1 -1\n0");
		else {
			_for (i, 0, n - 1)  if(P[i + 1])  _for (j, i + 1, n - 1)  _for (k, j, n - 1)  if (! (S ^ SG[n - i - 1] ^ SG[n - j - 1] ^ SG[n - k - 1])) {
				ans ++ ;
				if (ans == 1)  cout << i << " " << j << " " << k << endl;
			}
			cout << ans << endl;
		}
	}
	return 0;
}

100100 分代码(printf)

#include <bits/stdc++.h>
#define _for(i, a, b)  for (int i = (a); i <= (b); i ++ )
using namespace std;
const int N = 50;
int T, n, S, ans, SG[N], P[N], vis[N * N];
signed main() {
	ios :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
	SG[0] = 0;
	_for (i, 1, 22) {
		_for (j, 0, i - 1)  _for (k, 0, j)  vis[SG[j] ^ SG[k]] = 1;
		int id = 0;
		while (vis[id])  id ++ ;
		SG[i] = id;
		memset(vis, 0, sizeof(vis));
	}
	cin >> T;
	while (T -- ) {
		cin >> n, S = 0, ans = 0;
		_for (i, 1, n) {
			cin >> P[i];
			if (P[i] & 1)  S ^= SG[n - i];
		}
		if (! S)  puts("-1 -1 -1\n0");
		else {
			_for (i, 0, n - 1)  if(P[i + 1])  _for (j, i + 1, n - 1)  _for (k, j, n - 1)  if (! (S ^ SG[n - i - 1] ^ SG[n - j - 1] ^ SG[n - k - 1])) {
				ans ++ ;
				if (ans == 1)  printf("%d %d %d\n", i, j, k);
			}
			printf("%d\n", ans);
		}
	}
	return 0;
}
2022/10/1 21:16
加载中...