摘要: 描述给定一个数组包含n个元素,统计前m大的数并且把这m个数从大到小输出。输入第一行包含一个整数n,表示数组的大小。n < 100000。第二行包含n个整数,表示数组的元素,整数之间以一个空格分开。每个整数的绝对值不超过100000000。第三行包含一个整数m。m < n。输出从大到小输出前m大的数, 阅读全文
posted @ 2020-02-27 23:19 BlueValentines 阅读(239) 评论(0) 推荐(0)
摘要: #define _CRT_SECURE_NO_WARNINGS#include<iostream>using namespace std;void merge(int a[], int s, int m, int e, int temp[]) { int pb = 0; int p1 = s, p2 阅读全文
posted @ 2020-02-25 19:06 BlueValentines 阅读(112) 评论(0) 推荐(0)
摘要: 例题:逆波兰表达式逆波兰表达式是一种把运算符前置的算术表达式,例如普通的表达式2 + 3的逆波兰表示法为+ 2 3。逆波兰表达式的优点是运算符之间不必有优先级关系,也不必用括号改变运算次序,例如(2 +3) * 4的逆波兰表示法为* + 2 3 4。本题求解逆波兰表达式的值,其中运算符包括+ - * 阅读全文
posted @ 2020-02-25 18:15 BlueValentines 阅读(426) 评论(0) 推荐(0)
摘要: 一座很长的畜栏,包括N(2<=N<=100000)个隔间,这些小隔间的位置为x0,....xN-1(0<=xi<=1000000000,均为整数,各不相同) 将C(2<=C<=N)头奶牛每头分到一个隔间。牛都希望相互离得远,怎样才能使任意两头牛之间的最小距离尽可能的大,这个最小距离是多少? 题解: 阅读全文
posted @ 2020-02-25 14:58 BlueValentines 阅读(438) 评论(0) 推荐(0)
摘要: 输入n(n<=100000)个整数,找出其中两个数使之和为m。 题解: 解法一: #define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<algorithm>using namespace std; int main(){ int n[10 阅读全文
posted @ 2020-02-23 18:46 BlueValentines 阅读(246) 评论(0) 推荐(0)
摘要: 求方程的一个根:f(x)=x^3-5x^2+10x-80=0,要求|f(a)|<=10^-6。 题解:求导后可知该方程单增,且f(0)<0,f(100)>0。 #define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<cmath>using 阅读全文
posted @ 2020-02-23 17:31 BlueValentines 阅读(311) 评论(0) 推荐(0)
摘要: 在包含size个元素的,从小到大顺序的int数组a里查找比给定整数p小的,下标最大的元素,找不到返回-1 题解: int LowerBound(int a[],int size,int p) { int begin=0; int end=size-1; int pos=-1; while(begin 阅读全文
posted @ 2020-02-23 17:05 BlueValentines 阅读(293) 评论(0) 推荐(0)
摘要: 题解: #include<iostream>using namespace std;int r=0;void swap(int &a,int &b){ int t=a; a=b; b=t; }void sort(int s[],int l,int r,int n[],int c[]){ int mi 阅读全文
posted @ 2020-02-18 10:18 BlueValentines 阅读(142) 评论(0) 推荐(0)
摘要: 题解: 需要注意的是,快排完之后并不是按照编号从小到大的顺序输出 #include<iostream>using namespace std;int r=0;void swap(int &a,int &b){ int t=a; a=b; b=t; }void sort(int s[],int l,i 阅读全文
posted @ 2020-02-17 12:20 BlueValentines 阅读(110) 评论(0) 推荐(0)
摘要: 题解: 需要注意的是,快排完之后并不是按照编号从小到大的顺序输出 #include<iostream>using namespace std;int r=0;void swap(int &a,int &b){ int t=a; a=b; b=t; }void sort(int s[],int l,i 阅读全文
posted @ 2020-02-17 11:24 BlueValentines 阅读(151) 评论(0) 推荐(0)