本题思路较为清晰,考场时结构体内部数组开小了,导致wa。
#include <bits/stdc++.h>using namespace std;
#define ll long long
const int N = 1e5 + 10;
int v[10];
int a[10][4];
struct node
{int b[7];int num1 = 0;int c[7];int num2 = 0;int dx;int zhi;int tan; //坦克int zg;int oy;int bian;int fz;bool operator<(const node &t) const{if(t.fz != fz) return fz > t.fz;if(tan != t.tan) return tan > t.tan;if(zg != t.zg){return zg > t.zg;}if(zhi != t.zhi){return zhi > t.zhi;}if(dx != t.dx){return dx < t.dx;}if(oy != t.oy) return oy > t.oy;for(int i = 1; i <= num1 && i <= t.num1; i ++){if(b[i] != t.b[i]) return b[i] < t.b[i];}return num1 < t.num1;}
}q[100];
int main()
{for(int i = 1; i <= 6; i ++)cin >> v[i];int sum1 = 0, sum2 = 0, sum3 = 0;for(int i = 1; i <= 6; i ++){string s;cin >> s;for(int j = 1; j <= 3; j ++) a[i][j] = s[j - 1] - '0';}for(int i = 1; i <= 62; i++){int num1 = 0, num2 = 0; // 队伍数int s1 = 0, s2 = 0; // 人数之和int zhi1 = 0, zhi2 = 0; // 指挥数int gon1 = 0, gon2 = 0; // 工兵数int tan1 = 0, tan2 = 0; // 坦克数int minn = 6; // 最小的编号for(int j = 1; j <= 6; j ++){if(v[j] == 0) continue;if((i >> (j - 1))&1 == 1) //讨伐ou{//cout << pow(2, j - 1) << " ";q[i].b[++num1] = j;s1 += v[j];if(a[j][1] == 1) tan1 = 1;if(a[j][2] == 1) gon1 = 1;if(a[j][3] == 1) zhi1 = 1;minn = min(j, minn);}else{q[i].c[++num2] = j;s2 += v[j];if(a[j][1] == 1) tan2 = 1;if(a[j][2] == 1) gon2 = 1;if(a[j][3] == 1) zhi2 = 1;}}//cout << endl;q[i].num1 = num1;q[i].num2 = num2;q[i].dx = abs(s1 - s2);if(tan1 == tan2 && tan1 == 1) q[i].tan = 1;if(gon1 == 1 && gon2 == 1 && zhi1 == 1 && zhi2 == 1) q[i].zg = 1;if(zhi1 == 1 && zhi2 == 1) q[i].zhi = 1;if(s1 > s2) q[i].oy = 1;if(num1 == 0 || num2 == 0) q[i].fz = 0;else q[i].fz = 1;q[i].bian = minn;}sort(q + 1, q + 62 + 1);if(q[1].fz == 0 || q[1].tan == 0){cout << "GG" << endl;return 0;}for(int i = 1; i <= q[1].num1; i++){cout << q[1].b[i];if(i != q[1].num1) cout << " ";else cout << endl;}for(int i = 1; i <= q[1].num2; i++){cout << q[1].c[i];if(i != q[1].num2) cout << " ";else cout << endl;}return 0;
}
/*
6 8 7 5 3 0
010
101
010
001
011
000
6 8 7 5 3 0
010
101
110
001
111
000*/