diff --git a/TangDou/LuoGuBook/TestB.cpp b/TangDou/LuoGuBook/TestB.cpp index 7459580..2e8413f 100644 --- a/TangDou/LuoGuBook/TestB.cpp +++ b/TangDou/LuoGuBook/TestB.cpp @@ -1,32 +1,6 @@ #include using namespace std; -const int N = 110; -int getWuXu(string x){ - int sum = 0; - for (int i = 0; i < x.size(); i++) - for (int j = i + 1; j < x.size();j++) - if (x[i] > x[j]) sum++; - return sum; -} - -struct Node{ - int id; - string s; - int wxd; - const bool operator<(const Node &t){ - if (wxd == t.wxd) return id < t.id; - return wxd < t.wxd; - } -} a[N]; int main() { - int n, m; - cin >> n >> m; - for (int i = 0; i < m;i++){ - cin >> a[i].s; - a[i].id = i, a[i].wxd = getWuXu(a[i].s); - } - sort(a, a + m); - for (int i = 0; i < m;i++) - cout << a[i].s << endl; - return 0; + cout << round(1.0 * 1498 / 902) << endl; + return 0; } \ No newline at end of file diff --git a/TangDou/LuoGuBook/TestC.cpp b/TangDou/LuoGuBook/TestC.cpp new file mode 100644 index 0000000..c0b946c --- /dev/null +++ b/TangDou/LuoGuBook/TestC.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; +// 1498 902 +int main() { + int n, d; + cin >> n >> d; // 最后一个形式是: 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; // 将上一个小数的距离更新为现在小数的距离,为了下一次循环做准备工作 + } + } + + return 0; +} \ No newline at end of file diff --git a/TangDou/LuoGuBook/TestC.in b/TangDou/LuoGuBook/TestC.in new file mode 100644 index 0000000..7fb9c62 --- /dev/null +++ b/TangDou/LuoGuBook/TestC.in @@ -0,0 +1,8 @@ +2 +3 +ADAM +BOB +JOHNSON +2 +A AB C +DEF \ No newline at end of file