main
黄海 2 years ago
parent f6b3d6eed8
commit 1a070f67d9

@ -1,27 +1,18 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, num;
int ans;
vector<int> 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;
}

@ -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;
}

@ -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
https://blog.csdn.net/zhangdeniu/article/details/107720872
算法技巧-1909
https://blog.csdn.net/PROBIE_/article/details/105347265
Loading…
Cancel
Save