研究生算法课作业
仅保存本人算法课作业所用代码
spespusliar
这个作者很懒,什么都没留下…
展开
-
1027_带权活动选择
1027_带权活动选择 这题做的比较顺利,迫不及待想记录一下。 #include<iostream> using namespace std; //定义活动结构体,x表示活动开始时间,y表示活动结束时间,value表示这个活动的权重 struct activity { int x; int y; int value; }; //按照活动结束时间排序,这是预处理 void SortByEndtime(activity a[], int start, int end) { if (s原创 2021-11-23 21:50:49 · 376 阅读 · 0 评论 -
1010_二分搜索
常规二分搜索,挺简单的,注意不要把mid写成了low或者high #include<iostream> using namespace std; int father=-1; void bi_search(int Num[], int low, int high, int X) { if (low > high) { cout << "not found, father is " << father << endl; return; .原创 2021-10-10 13:51:45 · 102 阅读 · 0 评论 -
1007_最大乘积
最大乘积 #include<iostream> #include<string> using namespace std; int main() { int M; cin >> M; for(int iii=0;iii<M;iii++){ int K, N; char str[41]; //数字串 int i, j, k; cin >> N; //输入数字串的长度N cin >> K; //输入乘号个数原创 2021-10-03 17:29:45 · 102 阅读 · 0 评论 -
1006_堆排序
堆排序 (实际上是调整好的一个最小堆) 题解 #include<iostream> using namespace std; int main() { bool adjust = false; //用于控制循环,因为一轮并不一定能够完成最小堆的构建or调整 int m; cin >> m; for (int i = 0; i < m; i++) { int n; cin >> n; int* num; num = new int[n原创 2021-10-03 14:55:51 · 91 阅读 · 0 评论