From 1a070f67d92acd1de10fd033d666a036168f3ca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=B5=B7?= <10402852@qq.com> Date: Fri, 19 Jan 2024 20:37:48 +0800 Subject: [PATCH] 'commit' --- TangDou/LuoGuBook/TestBC.cpp | 31 ++++++++++------------------ TangDou/LuoGuBook/TestC.cpp | 3 --- TangDou/等级考试相关资料.txt | 6 +++++- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/TangDou/LuoGuBook/TestBC.cpp b/TangDou/LuoGuBook/TestBC.cpp index 0cc5efa..13a566e 100644 --- a/TangDou/LuoGuBook/TestBC.cpp +++ b/TangDou/LuoGuBook/TestBC.cpp @@ -1,27 +1,18 @@ #include - using namespace std; -const int N = 1e5 + 10; -int n, num; -int ans; -vector c; - int main() { - scanf("%d", &n); - for (num = 2;; num++) { - if (ans + num > n) break; - ans += num; - c.push_back(num); - } - - int r = n - ans; - while (r) { - for (int i = c.size() - 1; i >= 0 && r; i--) { - c[i] += 1; - r--; + int n, d; + cin >> n >> d; + double x = 1.0 * n / d; + double pre = round(x); + cout << pre << "/1" << endl; + for (int i = 1; i <= d; i++) { + for (int j = 1; j <= n; j++) { + double cur = 1.0 * j / i; + if (abs(cur - x) >= abs(pre - x)) continue; + cout << j << "/" << i << endl; + pre = cur; } } - for (int i = 0; i < c.size(); i++) printf("%d ", c[i]); - puts(""); return 0; } \ No newline at end of file diff --git a/TangDou/LuoGuBook/TestC.cpp b/TangDou/LuoGuBook/TestC.cpp index c0b946c..87e6e5c 100644 --- a/TangDou/LuoGuBook/TestC.cpp +++ b/TangDou/LuoGuBook/TestC.cpp @@ -4,7 +4,6 @@ using namespace std; int main() { int n, d; cin >> n >> d; // 最后一个形式是: n/d - // 最后一个数的小数 double x = 1.0 * n / d; double pre = round(x); // 前一个小数 @@ -20,10 +19,8 @@ int main() { if (abs(cur - x) >= abs(pre - x)) continue; // 如果当前枚举到的小数与最后小数的距离,大于,上一个小数与最后小数的距离 // 说明,现有枚举到的数更贴近目标,需要打印 cout << j << "/" << i << endl; - pre = cur; // 将上一个小数的距离更新为现在小数的距离,为了下一次循环做准备工作 } } - return 0; } \ No newline at end of file diff --git a/TangDou/等级考试相关资料.txt b/TangDou/等级考试相关资料.txt index b122c88..83f2505 100644 --- a/TangDou/等级考试相关资料.txt +++ b/TangDou/等级考试相关资料.txt @@ -11,4 +11,8 @@ https://www.xiaobaijidi.com/t/42451 https://ks.wjx.top/jq/96275141.aspx 全国青少年软件编程等级考试标准 (C 语言) -https://blog.csdn.net/zhangdeniu/article/details/107720872 \ No newline at end of file +https://blog.csdn.net/zhangdeniu/article/details/107720872 + + +算法技巧-1909 +https://blog.csdn.net/PROBIE_/article/details/105347265 \ No newline at end of file