最高输入只有100,感觉不会超时,直接暴力了
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
bool lossRow(vector<int>& a, vector<int>& b) {
if (a[1] < b[1]) return true;
return false;
}
bool resolutLossRow(vector<int>& a, vector<int>& b) {
if (a[0] < b[0]) return true;
else if (a[0] == b[0]){
if (a[1] < b[1]) return true;
else if (a[1] == b[1]){
if (a[2] < b[2]) return true;
}
}
return false;
}
bool compare(vector<int>& a, vector<int>& b) {
for (int i = 2; i < a.size(); i++) {
int tempa = a[i];
if (tempa == 0) continue;
for (int j = 2; j < b.size(); j++) {
int tempb = b[j];
if (tempb == 0) continue;
if (tempa == tempb) return false;
}
}
return true;
}
void solve(vector<vector<int>>& datas) {
sort(datas.begin(), datas.end(), lossRow);
vector<vector<int>> resolut;
// 记录数量
int one = -1;
int two = -1;
int three = -1;;
for (int i = 0; i < datas.size(); i++) {
if (datas[i][1] == 2 && one == -1) {
one = i - 1;
}
if (datas[i][1] == 3 && two == -1) {
two = i - 1;
}
}
three = datas.size() - 1;
for (int i = 0; i <= one; i++) {
for (int j = (one + 1); j <= two; j++) {
if (compare(datas[i], datas[j])) {
// 找 3
for (int k = two + 1; k < datas.size(); k++) {
if (compare(datas[i], datas[j]) && compare(datas[i], datas[k]) && compare(datas[j], datas[k])) {
vector<int> add(3);
add[0] = datas[i][0];
add[1] = datas[j][0];
add[2] = datas[k][0];
resolut.push_back(add);
}
}
}
}
}
if (resolut.empty()) {
cout << -1;
return ;
}
// 排序
sort(resolut.begin(), resolut.end(), resolutLossRow);
// 打印
for (vector<int> res : resolut) {
for (int id : res) {
cout << id << ' ';
}
cout << endl;
}
return;
}
int main() {
int n;
cin >> n;
vector<vector<int>> datas;
for (int i = 0; i < n; i++) {
vector<int> tempData(6);
for (int j = 0; j < 6; j++) cin >> tempData[j];
datas.push_back(tempData);
}
solve(datas);
return 0;
}

京公网安备 11010502036488号