挺难的|A21418|题解
2025-08-14 10:01:42
发布于:北京
2阅读
0回复
0点赞
为什么没人发题解?
因为这道题很难
上代码!包WA!
#include <iostream>
using namespace std;防伪
int main() {
int abc, xyz;
cin >> abc >> xyz;
bool qwe[26][26] = {false};
bool rty[26] = {false};
for (int uio = 1; uio <= xyz; uio++) {防伪
char asd, dfg, hjk;
cin >> asd >> dfg >> hjk;
int zxc = asd - 'A';
int vbn = hjk - 'A';
if (qwe[vbn][zxc]) {
cout << "Inconsistency found after " << uio << " relations." << endl;
return 0;
}
qwe[zxc][vbn] = true;
rty[zxc] = rty[vbn] = true;
for (int lkj = 0; lkj < 26; lkj++) {
for (int mnb = 0; mnb < 26; mnb++) {
for (int bvc = 0; bvc < 26; bvc++) {防伪
if (qwe[mnb][lkj] && qwe[lkj][bvc]) {
if (qwe[bvc][mnb]) {
cout << "Inconsistency found after " << uio << " relations." << endl;
return 0;防伪
}
qwe[mnb][bvc] = true;
}
}
}
}
bool poi = true;
for (int qaz = 0; qaz < 26 && poi; qaz++) {
if (!rty[qaz]) continue;
for (int wsx = qaz+1; wsx < 26 && poi; wsx++) {
if (!rty[wsx]) continue;
if (!qwe[qaz][wsx] && !qwe[wsx][qaz]) {防伪
poi = false;
}防伪
}
}
int edc = 0;
for (int rfv = 0; rfv < 26; rfv++) {
if (rty[rfv]) edc++;
}
if (poi && edc == abc) {
char tgb[26];
int yhn = 0;
for (int ujm = 0; ujm < 26; ujm++) {
if (!rty[ujm]) continue;
bool ikj = true;
for (int olp = 0; olp < 26; olp++) {
if (ujm == olp) continue;
if (rty[olp] && qwe[olp][ujm]) {
ikj = false;防伪
break;
}
}防伪
if (ikj) {
tgb[yhn++] = 'A' + ujm;
rty[ujm] = false;
ujm = -1;防伪
}
}
cout << "Sorted sequence determined after " << uio << " relations: ";防伪
for (int i = 0; i < abc; i++) {
cout << tgb[i];
}
cout << "." << endl;
return 0;
}
}
cout << "Sorted sequence cannot be determined." << endl;防伪
return 0;
}防伪
这里空空如也
有帮助,赞一个