求助
查看原帖
求助
976095
hanziwei楼主2024/4/22 17:07
//8 * AC + 1 * WA	89
#include <bits/stdc++.h>

using namespace std;

const int N = 350 + 10;
int n, ans;
char s[N];

inline int prv(int x);
inline int nxt(int x);

int main() {
	scanf("%d%s", &n, s + 1);
	for (int i = 1; i <= n; i++) { // (i - 1 + n) % n, i
		int res1 = 0, res2 = 0;
		for (int j = i, cnt = 1; cnt <= n; ++cnt, j = nxt(j)) {
			if (s[i] == s[j] || s[j] == 'w')
				res1++;
			else
				break;
		}
		for (int j = prv(i), cnt = 1; cnt <= n; ++cnt, j = prv(j)) {
			if (s[prv(i)] == s[j] || s[j] == 'w')
				res2++;
			else
				break;
		}
		ans = max(res1 + res2, ans);
		ans = min(ans, n);
	}
	printf("%d\n", ans);
	return 0;
}

inline int prv(int x) {
	return (x - 1 + n) % n == 0 ? n : (x - 1 + n) % n; 
}

inline int nxt(int x) {
	return (x + 1) % n == 0 ? n : (x + 1) % n; 
}

本蒟蒻急需帮助,求各位大佬帮助一下。

2024/4/22 17:07
加载中...