1562C - Rings
原创
©著作权归作者所有:来自51CTO博客作者whiteawll的原创作品,请联系作者获取转载授权,否则将追究法律责任
https://codeforces.com/contest/1562/problem/C
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
void solve() {
string s;
int n;
cin >> n;
cin >> s;
int k = - 1;
for (int i = 0; i < n; i ++) {
if (s[i] == '0') {
k = 1;
if (i>= n / 2) cout << 1 << ' ' << i + 1 << " " << 1 << " " << i << endl;
else cout << i + 2 << " " <<n << " " << i + 1 << ' ' << n << endl;
break;
}
}
if (k == - 1) {
cout << 1 << ' ' << n- 1 << ' ' << 2 << " " << n << endl;
}
}
int main () {
int t;
cin >> t;
while (t --) solve();
return 0;
}
考虑哪些k容易计算,1, 2 0 先考虑极端形况[1, n - 1] [2, n] 只要找到一个0位置为k,如果这个k在左半边,那么[k, n] [k + 1, n] 否则[1, k] [1, k - 1];