趣味编程
乐行僧丶
这个作者很懒,什么都没留下…
展开
-
递归逆序和正数输出正整数
正序输出 #include <bits/stdc++.h> using namespace std; void print(int x) { if (x == 0) return; print(x/10); cout << x%10 << " "; } 逆序输出 #include <bits/stdc++.h> using namespace std; void reversePrint(int x) { if (x == 0) { retu原创 2020-11-15 16:24:14 · 594 阅读 · 0 评论 -
求解逆序对的个数(由归并排序衍生出的O(nlogn)时间复杂度的算法)
逆序:在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么它们就称为一个逆序。 一、暴力做法 int count(int *a, int n) { int res = 0; for (int i=0; i<n-1; ++i) { for (int j=1; j<n; ++j) { if (a[i] > a[j]) res ++; } ...原创 2019-11-19 11:55:40 · 577 阅读 · 0 评论 -
汉诺塔问题的求解
代码实现: #include <iostream> using namespace std; void move(char a, char c) {cout << a << "->" << c << endl;} void hanoi(int n, char a, char b, char c) { //如果只有一个盘子 直...原创 2019-09-10 11:29:38 · 337 阅读 · 0 评论 -
XJT软件考研真题:判断xx年xx月xx日是当年的第几天
#include <iostream> #include <cstring> #include <algorithm> #include <map> using namespace std; int month[2][13] = { {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, ...原创 2019-09-30 16:54:16 · 179 阅读 · 0 评论