电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

acm基本算法大全

140页
  • 卖家[上传人]:xins****2008
  • 文档编号:104969517
  • 上传时间:2019-10-10
  • 文档格式:DOC
  • 文档大小:536.50KB
  • / 140 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • 1、第一章 排序、顺序统计与解题的基本策略1.1计数排序/ 计数排序.cpp : Defines the entry point for the console application./计数排序,输入数字,在0100之间,数字个数一般远多于100#include stdafx.h#include using namespace std;int main(int argc, char* argv)int n;while(cinn)int count101=0,arrayA10000,arrayB10000,i;for(i=0;iarrayAi;countarrayAi+;for(i=1;i101;i+)counti+=counti-1;for(i=0;in;i+)arrayB-countarrayAi=arrayAi;for(i=0;in;i+)coutarrayBi ;coutendl;return 0;1.2 快速排序/ 快速排序sort和qsort.cpp : Defines the entry point for the console application./#include

      2、stdafx.h#include #include #include using namespace std;typedef struct int x,y;Node;bool cmpfn(Node a,Node b)return a.xn,i=0;iarrayi.xarrayi.y;sort(array,array+n,cmpfn);/qsort(array,n,sizeof(arrayi),Cmp);for(i=0;in;i+)coutarrayi.x arrayi.yendl;return 0;1.3稳定排序/ 稳定排序.cpp : Defines the entry point for the console application./#include stdafx.h#include #include #include using namespace std;/从小到大排序bool cmpfn(int a,int b)return ab;*/int main(int argc, char* argv)int i,n,array100;for(cinn,i=0;iarrayi;s

      3、table_sort(array,array+n,cmpfn);for(i=0;in;i+)coutarrayi ;coutendl;return 0;1.4堆排序/ 堆排序.cpp : Defines the entry point for the console application./*堆排序排成完全二叉树,满足一下性质: 1.如果某节点有孩子,则根节点的值都小于孩子节点的值。我们称之为小堆根 2.如果某节点有孩子,则根节点的值都大于孩子节点的值。我们称之为大堆根以小堆根为例,根节点是最小值,次小值在根节点的两个孩子中 调整建堆的时间复杂度为W(lbn)小根堆 */#include stdafx.h#include using namespace std;void DownHeap(int heap,int r,int len)int i,s=heapr;i=r1;while(i=len)if(i+1=len & heapi+1heapi)i+;if(heapis)heapr=heapi;r=i;i=r1;while(i0 & s1;heapr=s;void MakeHeap(

      4、int heap,int len)for(int i=len1;i0;i-)DownHeap(heap,i,len);void PushHeap(int heap,int x,int &len)heap+len=x;UpHeap(heap,len,len);void PopHeap(int heap,int &x,int &len)x=heap1;heap1=heaplen;DownHeap(heap,1,-len);void PrintHeap(int heap,int len)int i=len,x,a100;while(i0)PopHeap(heap,x,i);alen-i=x;for(i=1;i=len;i+)coutai ;coutlen)int heap100,i;for(i=1;iheapi;MakeHeap(heap,len);/PrintHeap(heap,len);PushHeap(heap,10,len);PrintHeap(heap,len);return 0;1.5“二分思想”/ 快速排序.cpp : Defines the entry point for t

      5、he console application./*快速排序体现了“二分”的思想,排序的时间复杂度为nlog2(n),速度最快其排序分成三个步骤:分解、解决和合并 */#include stdafx.h#include using namespace std;void QuickSort(int array,int st,int ed)if(sted)int temp=array(ed+st)/2,i=st,j=ed;while(ij)while(arrayitemp)j-;if(in)int array10000,i;for(i=0;iarrayi;QuickSort(array,0,n-1);for(i=0;in;i+)coutarrayi ;coutendl;return 0;/ 最近点对.cpp : Defines the entry point for the console application./#include #include#include #include #include using namespace std;const int N = 100005;cons

      6、t double MAX = 10e100;const double eps = 0.00001;typedef struct TYPEdouble x, y;int index; Point;Point aN, bN, cN;double closest(Point *, Point *, Point *, int, int);double dis(Point, Point);int cmp_x(const void *, const void*);int cmp_y(const void *, const void*);int merge(Point *, Point *, int, int, int);inline double min(double, double);int main()int n, i;double d;scanf(%d, &n);while (n)for (i = 0; i n; i+)scanf(%lf%lf, &(ai.x), &(ai.y);qsort(a, n, sizeof(a0), cmp_x);for (i = 0; i n; i+)ai.index = i;memcpy(b, a, n *sizeof(a0);qsort(b, n, sizeof(b0), cmp_y);d = closest(a, b, c, 0, n - 1);printf(

      《acm基本算法大全》由会员xins****2008分享,可在线阅读,更多相关《acm基本算法大全》请在金锄头文库上搜索。

      点击阅读更多内容
    最新标签
    监控施工 信息化课堂中的合作学习结业作业七年级语文 发车时刻表 长途客运 入党志愿书填写模板精品 庆祝建党101周年多体裁诗歌朗诵素材汇编10篇唯一微庆祝 智能家居系统本科论文 心得感悟 雁楠中学 20230513224122 2022 公安主题党日 部编版四年级第三单元综合性学习课件 机关事务中心2022年全面依法治区工作总结及来年工作安排 入党积极分子自我推荐 世界水日ppt 关于构建更高水平的全民健身公共服务体系的意见 空气单元分析 哈里德课件 2022年乡村振兴驻村工作计划 空气教材分析 五年级下册科学教材分析 退役军人事务局季度工作总结 集装箱房合同 2021年财务报表 2022年继续教育公需课 2022年公需课 2022年日历每月一张 名词性从句在写作中的应用 局域网技术与局域网组建 施工网格 薪资体系 运维实施方案 硫酸安全技术 柔韧训练 既有居住建筑节能改造技术规程 建筑工地疫情防控 大型工程技术风险 磷酸二氢钾 2022年小学三年级语文下册教学总结例文 少儿美术-小花 2022年环保倡议书模板六篇 2022年监理辞职报告精选 2022年畅想未来记叙文精品 企业信息化建设与管理课程实验指导书范本 草房子读后感-第1篇 小数乘整数教学PPT课件人教版五年级数学上册 2022年教师个人工作计划范本-工作计划 国学小名士经典诵读电视大赛观后感诵读经典传承美德 医疗质量管理制度 2
    关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
    手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
    ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.