题意
判断哪两个人是狼。
思路
假设两只狼,进行校验。
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
vector<int> v(n+1);
for (int i = 1; i <= n; ++i) cin >> v[i];
for (int i = 1; i <= n; ++i) {
for (int j = i + 1; j <= n; ++j) {
vector<int> lie, a(n + 1, 1);
a[i] = a[j] = -1;
for (int k = 1; k <= n; k++)
if (v[k] * a[abs(v[k])] < 0) lie.push_back(k);
if (lie.size() == 2 && a[lie[0]] + a[lie[1]] == 0) {
cout << i << " " << j << '\n';
exit(0);
}
}
}
cout << "No Solution\n";
return 0;
}
HINT
不定时更新更多题解,Basic Level 全部AC代码,详见 link ! ! !