From 2eeb4fa09b4d2941c5717508449c11d13d7e156b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=B5=B7?= <10402852@qq.com> Date: Wed, 3 Jan 2024 13:14:08 +0800 Subject: [PATCH] 'commit' --- TangDou/AcWing_TiGao/T3/Floyd/343_1.cpp | 43 ++++++++++++------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/TangDou/AcWing_TiGao/T3/Floyd/343_1.cpp b/TangDou/AcWing_TiGao/T3/Floyd/343_1.cpp index e2df5ac..7283744 100644 --- a/TangDou/AcWing_TiGao/T3/Floyd/343_1.cpp +++ b/TangDou/AcWing_TiGao/T3/Floyd/343_1.cpp @@ -27,20 +27,19 @@ int check() { return 1; // 找到顺序 } -char get_min() { - for (int i = 0; i < n; i++) - if (!st[i]) { - bool flag = true; - for (int j = 0; j < n; j++) - if (!st[j] && g[j][i]) { // 如果存在j> s; int a = s[0] - 'A', b = s[2] - 'A'; // A->0,B->1,...,Z->25完成映射关系 - if (!type) { // 如果不存在矛盾,就尝试找出大小的顺序 - g[a][b] = 1; // 有边 - floyd(); // 求传递闭包 - type = check(); // 检查是不是存在矛盾,或者找到了完整的顺序 - if (type) t = i; // 如果找到了顺序,记录是第几次输入后找到顺序 + if (!type) { // 如果不存在矛盾,就尝试找出大小的顺序 + g[a][b] = 1; // 有边 + floyd(); // 求传递闭包 + type = check(); // 检查是不是存在矛盾,或者找到了完整的顺序 + if (type > 0) t = i; // 如果找到了顺序,或者发现了矛盾,记录是第几次输入后发现的 } // 即使存在矛盾,也需要继续读入,直到本轮数据读入完成 } @@ -67,10 +66,8 @@ int main() { else if (type == 2) printf("Inconsistency found after %d relations.\n", t); else { - memset(st, 0, sizeof st); - printf("Sorted sequence determined after %d relations: ", t); - for (int i = 0; i < n; i++) printf("%c", get_min()); - printf(".\n"); + string ans = getorder(); // 输出升序排列的所有变量 + printf("Sorted sequence determined after %d relations: %s.\n", t, ans.c_str()); } } return 0;