ACM学习<3>
1.冒泡排序:
| #include <iostream> #include <time.h> #define SIZE 10 using namespace std; void BubbleSort(int *a,int len) { int temp; for(int i=0;i<len-1;i++) { for(int j=len-1;j>i;j--) { if(a[j-1]>a[j]) { temp=a[j]; a[j]=a[j-1]; a[j-1]=temp; } } cout<<i<<":"; for(int k=0;k<len;k++) { cout<<a[k]<<" "; } cout<<endl; } } int main() { int shuzu[SIZE]; srand(time(NULL));//随机种子 for(int i=0;i<SIZE;i++) { shuzu[i]=rand()/1000+100; } cout<<"old:"; for(int i=0;i<SIZE;i++) { cout<<shuzu[i]<<" "; } cout<<endl; BubbleSort(shuzu,SIZE); cout<<"now:"; for(int i=0;i<SIZE;i++) { cout<<shuzu[i]<<" "; } cout<<endl; } |
| #include <iostream> #include <time.h> using namespace std; #define SIZE 10 void SelectionSort(int *a,int len) { int temp,k; for(int i=0;i<len-1;i++) { k=i; for(int j=i+1;j<len-1;j++) { if(a[j]<a[k]) k=j; } if(k!=i)//交换 { temp=a[k]; a[k]=a[i]; a[i]=temp; } } } int main() { int shuzu[SIZE]; srand(time(NULL)); for(int i=0;i<SIZE;i++) { shuzu[i]=rand()/1000+100; } cout<<"old:"; for(int i=0;i<SIZE;i++) { cout<<shuzu[i]<<" "; } cout<<endl; SelectionSort(shuzu,SIZE); cout<<"now:"; for(int i=0;i<SIZE;i++) { cout<<shuzu[i]<<" "; } cout<<endl; } |
| #include <iostream> #include <time.h> #define SIZE 10 using namespace std; void InsertionSort(int *a,int len) { int temp,j,i,k; for(i=1;i<len;i++) { //temp=a[i],a[j+1]=a[j];a[j+1]=temp;就是个交换。 判断 j-- 为逻辑 temp=a[i], j=i-1; while(j>=0 && temp<a[j]) { a[j+1]=a[j]; j--; } a[j+1]=temp; } } int main() { int arr[SIZE]; srand(time(NULL)); for(int i=0;i<SIZE;i++) { arr[i]=rand()/1000+100; } cout<<"old:"; for(int j=0;j<SIZE;j++) { cout<<arr[j]<<" "; } cout<<endl; InsertionSort(arr,SIZE); cout<<"now:"; for(int k=0;k<SIZE;k++) { cout<<arr[k]<<" "; } cout<<endl; } |
| #include <iostream> #include <time.h> using namespace std; #define SIZE 10 void ShellSrot(int *a,int len) |
ACM学习<3>的更多相关文章
- ACM学习-POJ-1143-Number Game
菜鸟学习ACM,纪录自己成长过程中的点滴. 学习的路上,与君共勉. ACM学习-POJ-1143-Number Game Number Game Time Limit: 1000MS Memory ...
- ACM学习-POJ-1125-Stockbroker Grapevine
菜鸟学习ACM,纪录自己成长过程中的点滴. 学习的路上,与君共勉. ACM学习-POJ-1125-Stockbroker Grapevine Stockbroker Grapevine Time Li ...
- ACM学习-POJ-1003-Hangover
菜鸟学习ACM,纪录自己成长过程中的点滴. 学习的路上,与君共勉. ACM学习-POJ-1003-Hangover Hangover Time Limit: 1000MS Memory Limit ...
- ACM学习-POJ-1004-Financial Management
菜鸟学习ACM,纪录自己成长过程中的点滴. 学习的路上,与君共勉. ACM学习-POJ-1003-Financial Management Financial Management Time Limi ...
- acm学习指引
acm学习心得及书籍推荐 一般要做到50行以内的程序不用调试.100行以内的二分钟内调试成功.acm主要是考算法的,主要时间是花在思考算法上,不是花在写程序与debug上. 下面给个计划练练: 第 ...
- ACM学习
转:ACM大量习题题库 ACM大量习题题库 现在网上有许多题库,大多是可以在线评测,所以叫做Online Judge.除了USACO是为IOI准备外,其余几乎全部是大学的ACM竞赛题库. US ...
- 完成了C++作业,本博客现在开始全面记录acm学习历程,真正的acm之路,现在开始
以下以目前遇到题目开始记录,按发布时间排序 ACM之递推递归 ACM之数学题 拓扑排序 ACM之最短路径做题笔记与记录 STL学习笔记不(定期更新) 八皇后问题解题报告
- ACM学习历程—HDU 5512 Pagodas(数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5512 学习菊苣的博客,只粘链接,不粘题目描述了. 题目大意就是给了初始的集合{a, b},然后取集合里 ...
- ACM学习历程—HDU5521 Meeting(图论)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5521 学习菊苣的博客,只粘链接,不粘题目描述了. 题目大意就是一个人从1开始走,一个人从n开始走.让最 ...
- ACM学习网站、
转载:http://www.cnblogs.com/zhourongqing/archive/2012/05/24/2516180.html http://61.187.179.132/JudgeOn ...
随机推荐
- Shell中read命令--学习
read命令 -p(提示语句) -n(字符个数) -t(等待时间) -s(不回显) 1.基本读取read命令接收标准输入(键盘)的输入,或其他文件描述符的输入(后面在说).得到输入后,read命令将数 ...
- sublime text3 使用问题积累
1.安装完后,注册码:注意!要把下列内容完全拷贝过去,包含"-------BEGIN LICENSE------和------END LICENSE--------" ----- ...
- echart.js在vue中使用
以前可能写过,懒得去翻了,再写一次 1,安装echarts 导入到页面 import echarts from 'echarts'; 2.在生命周期里面做初始化 data(){ return{ t ...
- 什么叫做API?看完你就理解了
阅读编程资料时经常会看到API这个名词,网上各种高大上的解释估计放倒了一批初学者.初学者看到下面这一段话可能就有点头痛了. API(Application Programming Interface, ...
- ubuntu,day 2 ,退出当前用户,创建用户,查找,su,sudo,管道符,grep,alias,mount,tar解压
本节内容: 1,文件权限的控制,chmod,chown 2,用户的增删和所属组,useradd,userdel 3,用户组的增删,groupadd,groupdel 4,su,sudo的介绍 5,别名 ...
- NCUAP 利用java自带方法实现导入excel取数据
final JComponent parent = getModel().getContext().getEntranceUI(); JFileChooser chooser = new JFileC ...
- python08内置函数
https://www.cnblogs.com/xiao1/p/5856890.html 1 .all(可迭代对象),对每个元素进行布尔运算,全部为真,函数结果就为真,否则为假 参数为一个整体的情况例 ...
- redis在游戏服务器中的使用初探(二) 客户端开源库选择
上文提到 搭建完成后 我们选择客户端的开源库进行连接 有以下三种选择 1 acl-redis 原因是支持VC 国产 作者博客 acl 框架库简介 用 acl 库编写高效的 C++ redis ...
- 2019.03.01 bzoj2555: SubString(sam+lct)
传送门 题意简述: 要求在线支持两个操作 (1):在当前字符串的后面插入一个字符串 (2):询问字符串s在当前字符串中出现了几次?(作为连续子串) 思路: 考虑用lctlctlct来动态维护samsa ...
- 理解React组件的生命周期
本文作者写作的时间较早,所以里面会出现很多的旧版ES5的时代的方法.不过,虽然如此并不影响读者理解组件的生命周期.反而是作者分为几种不同的触发机制来解释生命周期的各个方法,让读者更加容易理解涉及到的概 ...