这题我觉得真的有点烦,我想了半天还是没全对。。。还是参考大神的。。。
1 #include <iostream> 2 #include <stdlib.h> 3 #include <string> 4 #include<algorithm> 5 #include<vector> 6 #include<cmath> 7 #include<map> 8 #include<set> 9 #include <unordered_map> 10 using namespace std; 11 12 int main(){ 13 int n; 14 vector<int> arr(101); 15 cin >> n; 16 for (int i = 0; i < n; i++) { 17 cin >> arr[i + 1]; 18 } 19 int w1 = -1, w2 = -1; 20 for (int i = 1; i <= n; i++) { 21 for (int j = 1; j <= n; j++) { 22 if (j == i) { 23 continue; 24 } 25 else { 26 vector<int> lier, wolf(n + 1, 1); 27 wolf[i] = wolf[j] = -1; 28 29 for (int k = 1; k <= n; k++) { 30 if (arr[k] * wolf[abs(arr[k])] < 0) { 31 lier.push_back(k); 32 } 33 } 34 35 if (lier.size() == 2 && wolf[lier[0]] + wolf[lier[1]] == 0) { 36 w1 = i; 37 w2 = j; 38 goto p1; 39 40 } 41 42 } 43 } 44 } 45 46 p1: 47 if (w1 ==-1) { 48 cout << "No Solution" << endl; 49 } 50 else { 51 cout << w1 << ‘ ‘ << w2 << endl; 52 } 53 54 system("pause"); 55 };
原文地址:https://www.cnblogs.com/wsggb123/p/10225314.html
时间: 2024-11-06 11:39:12