- 博客(7)
- 收藏
- 关注
原创 算法导论第三版第二章答案
第二章1-1 1-2 1-3 1-41-1Using figure 2-2 as a model, illustrate the operations of Insertion-Sort on the array A=⟨31,41,59,26,41,58⟩.以图2-2为模型,说明Insertion-Sort在数组A=⟨31,41,59,26,41,58⟩上的执行情况1-2Rewrite the Insertion-Sort procedure to sort into nonincreas
2021-04-26 22:17:16
1040
原创 算法导论第三版第一章答案
第一章1-1 1-2 1-3 1-4 1-52-1 2-2 2-31-1Give a real-world example that requires sorting or a real-world example that requires computing a convex hull.给出现实生活中需要排序的一个例子或者现实生活中需要计算凸壳的一个例子排序的例子有学校里的成绩排名、字典里面单词按字母排序、网页按热度排序等,而计算凸壳的话感觉没什么例子,好像居民区划分的时候有可能会用到。
2021-04-26 19:25:35
427
原创 洛谷P1554梦中的统计
非暴力解法本人最讨厌循环枚举代码如下#include<iostream>int fun(int, int);int main(){ using namespace std; int m, n; int count[10] = { 0 }; cin >> m >> n; for (int j = 0; j < 10; j++) { count[j] = fun(n, j) - fun(m - 1, j); cout << c
2021-04-07 20:24:39
196
原创 洛谷P1217回文质数
非打表解法听说有人打表过了,果然大佬思维就是不一样可怜我老老实实用了递归函数prime判断一个数是否是质数digit_count返回数字的位数fun输出回文质数代码如下:#include<iostream>#include<cmath>bool prime(int x);void fun(int n, int x, int sum, int m);int digit_count(int x);int y, z;int main(){
2021-04-05 10:37:25
116
原创 洛谷P1980计数问题(非暴力)
非暴力解法纯暴力当然可解,那就不需要题解了话不多说,先上代码#include<iostream>int main(){ using namespace std; int n, x, count = 0; cin >> n >> x; int a, b, c; int k = 1; while (k <= n) { a = n / k / 10; b = n / k % 10; c = n % k; if (x) {
2021-04-03 19:29:37
84
原创 选择排序,冒泡排序,剃刀排序,插入排序
排序算法本文注意1选择排序估计这是最简单的排序算法了算法复杂度O(n2)直接上代码void select_sort(int* a, int n){ int t; for(int i=0;i<n-1;i++) for (int j = i + 1; j < n; j++) { if (a[i] < a[j]) t = a[i], a[i] = a[j], a[j] = t; }}复杂度分析循环执行((n-1)+(n-2)+(n-3)+……+
2021-03-31 23:18:00
89
原创 洛谷P5729工艺品制作
纯模拟的水题先设一个三维数组,初始化为0计算原来体积嵌套循环,如果数据为0就设为1并用原来体积减去1代码如下#include<iostream> using namespace std; int main() { int x1, x2, y1, y2, z1, z2; int a[20][20][20] = { 0 }; int w, x, h, q; cin >> w >> x >> h
2021-03-28 20:22:01
237
2
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人