parent
1c5efff3e8
commit
65958ee9dd
@ -1,32 +1,6 @@
|
|||||||
#include <bits/stdc++.h>
|
#include <bits/stdc++.h>
|
||||||
using namespace std;
|
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 main() {
|
||||||
int n, m;
|
cout << round(1.0 * 1498 / 902) << endl;
|
||||||
cin >> n >> m;
|
return 0;
|
||||||
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;
|
|
||||||
}
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
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;
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
2
|
||||||
|
3
|
||||||
|
ADAM
|
||||||
|
BOB
|
||||||
|
JOHNSON
|
||||||
|
2
|
||||||
|
A AB C
|
||||||
|
DEF
|
Loading…
Reference in new issue