
程设
Liusyu6688
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
二分搜索
//写一个函数BinarySeach,在包含size个元素的、从小到大排序的int数组a里查找元素//p,如果找到,则返回元素下标,如果找不到,则返回-1。要求复杂度O(log(n))#include<iostream>#include<algorithm>using namespace std;int BinarySearch(int a[],int size,...原创 2018-07-25 14:53:49 · 209 阅读 · 0 评论 -
二分搜索小的最大值
//写一个函数LowerBound,在包含size个元素的、从小到大排序的int数组a里查找比给//定整数p小的,下标最大的元素。找到则返回其下标,找不到则返回-1#include<iostream>using namespace std;#include<algorithm>int LowerBound(int a[],int size,int p){ ...原创 2018-07-25 15:12:53 · 344 阅读 · 0 评论 -
二分法解方程
#include<iostream>#include<algorithm>using namespace std;double EPS=1e-6;double f(double x) { return x*x*x - 5*x*x + 10*x - 80; }int main(){ double l=0; double r=100; do...原创 2018-07-25 15:30:06 · 1022 阅读 · 0 评论 -
找出和为定值的数对
输入n ( n<= 100,000)个整数,找出其中的两个数,它们之和等于整数m(假定 肯定有解)。题中所有整数都能用 int 表示 解法一:1) 将数组排序,复杂度是O(n×log(n)) 2) 查找的时候,设置两个变量i和j,i初值是0,j初值是n-1.看a[i]+a[j],如果大于m, 就让j减1,如果小于m,就让i加1,直至a[i]+a[j]=m...原创 2018-07-25 15:38:27 · 544 阅读 · 0 评论 -
分治
把一个任务,分成形式和原任务相同,但规模更小的 几个部分任务(通常是两个部分),分别完成,或只需要选一部完成。然后再处理完成后的这一个或几个 部分的结果,实现整个任务的完成。 归并排序 https://www.cnblogs.com/chengxiao/p/6194356.html(图解) #include <iostream>...原创 2018-07-26 10:08:06 · 607 阅读 · 0 评论 -
股票问题(分治)
股票买卖 查看 提交 统计 提问 总时间限制: 1000ms 内存限制: 65536kB 描述 最近越来越多的人都投身股市,阿福也有点心动了。谨记着“股市有风险,入市需谨慎”,阿福决定先来研究一下简化版的股票买卖问题。 假设阿福已经准确预测出了某只股票在未来 N 天的价格,他希望买卖两次,使得获得的利润最高。为了计算简单起见,利润的计算方式为卖出的价格减去买入的价格。 ...原创 2018-07-26 10:10:03 · 2185 阅读 · 0 评论 -
二分的一些收获
二分搜索函数: #include&lt;iostream&gt;using namespace std;#include&lt;algorithm&gt;int rfind(int a[],int mm,int num){ int l=0,r=num-1; while(l&lt;=r) { int m=l+(r-l)/2;...原创 2018-08-01 14:03:51 · 252 阅读 · 0 评论 -
格式化输出
DescriptionAnonymous has met a problem.To solve this problem, he has to write 4 classes.These classes are point, vector, circle and todo. point / \ / \ vecto...原创 2018-06-07 15:49:58 · 279 阅读 · 0 评论 -
[Inheritance & Polymorphism] Destructor
DestructorDescription 下面是不完整的继承类定义:class A{public:virtual void Prin(){cout<<"Prin come form class A"<<endl;}};class B{ char *buf;public: void Prin(){cout<<"...原创 2018-06-07 16:04:35 · 439 阅读 · 0 评论 -
利用动态规划来求出连续項的最大和
#include <iostream>using namespace std;int max(int a,int b){ return a>b?a:b;}int main(int argc, const char * argv[]){ int num; cin>>num; int arr[num]; for(int ...原创 2018-06-09 15:03:07 · 176 阅读 · 0 评论