其他分享
首页 > 其他分享> > 1594C - Make Them Equal

1594C - Make Them Equal

作者:互联网

思路:

经观察,可发现答案$\le\(2,因为两个数\)n\(和\)n-1$可以筛到所有数。
依次枚举每个小标的倍数即可

代码:

#include <iostream>
using namespace std;
int n;
char ch;
string s;
int main () {
	int T;
	cin >> T;
	while (T--) {
		cin >> n >> ch >> s;
		s = ' '+s;
		bool is_all_ch = true;
		for (int i = 1;i <= n;i++) {
			if (s[i] != ch) is_all_ch = false;
		}
		if (is_all_ch) {
			cout << 0 << endl;
			continue;
		}
		bool has_ans = false;
		for (int i = 1;i <= n;i++) {
			int cnt = 0;
			for (int j = i;j <= n;j += i) {
				if (s[j] != ch) cnt++;
			}
			if (cnt == 0) {
				cout << 1 << endl << i << endl;
				has_ans = true;
				break;
			}
		}
		if (!has_ans) cout << 2 << endl << n << ' ' << n-1 << endl;
	}
	return 0;
}

标签:Them,ch,int,Make,cin,char,1594C
来源: https://www.cnblogs.com/incra/p/16420945.html