ImageVerifierCode 换一换
格式:DOCX , 页数:15 ,大小:37.90KB ,
资源ID:16348083      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/16348083.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(exercise2 ACM文档格式.docx)为本站会员(b****3)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

exercise2 ACM文档格式.docx

1、Begina1Enda1= BeginanEndan;可以证明,如果在可能的事件a1Number; /判断事件个数是否超出上限 if(NumberMax) cout事件个数超出上限!endl; exit(1); /输入时间序列 for(int j=0;jBeginjEndj; /寻找最长的时间序列 /首先将第一个最早结束的事件加入最长时间序列 result0=0; /继续循环遍历所有事件构造最长时间序列 for(int i=1;i=Endresultr) result+r=i; /输出最长时间序列编号 for(int k=0;k=r;k+)resultkt; cout区间覆盖问题:2、用i来表

2、示x轴上坐标为i-1,i的区间(长度为1),并给出M(1=M=200)个不同的整数,表示M个这样的区间。现在让你画几条线段覆盖住所有的区间,条件是:每条线段可以任意长,但是要求所画线段之和最小,并且线段的数目不超过N(1=N=b;int main() int n,m,minLength,max;/区间点的个数n和所需的线段数m,覆盖线段的最短总长度minLength,区间点编号的最大数max int point200,distance200;/区间点数组point与区间点之间的距离数组distance while(cinnm)/用户输入区间点的个数n和所需的线段数mmax;/输入区间点编号的最

3、大数,为0程序退出 if(!max) break; for(int i=0;n; cinpointi; sort(point,point+n);/升序排列 minLength=pointn-1-point0+1;/全部覆盖的最长的一条线段的长度 for(i=0;n-1; distancei=pointi+1-pointi-1;/将每两个区间点之间的距离存入distance数组 int nn=n-1;/距离数组的实际长度 sort(distance,distance+nn,descend);/将区间距离数组降序排列m-1; minLength-=distancei;/将链接区间点之间的线段按先去

4、长后去短的顺序一一去掉知道线段条数达到要求minLength0,其余的都是必胜点。/3.取石子(The Game of Nim)/判断是不是2的幂bool isPowerOf2(int n) int number=n; while(number) if(number=1) return true; if(number%2) return false; number/=2; return true; /石子的初始数目 if(Number=0)win! if(isPowerOf2(Number+1)lose! else【估计也不会考这个】母函数:4、Given some Chinese Coins

5、 (three kinds- 1, 2, 5), and their number is num_1, num_2 and num_5 respectively, please output the minimum value that you cannot pay with given coins.InputInput contains multiple test cases. Each test case contains 3 positive integers num_1, num_2 and num_5 (0=num_i=1000). A test case containing 0

6、0 0 terminates the input and this test case is not to be processed.OutputOutput the minimum positive value that one cannot pay with given coins, one line for one case.题目大意为给你三种不同价值的硬币,分别为一、二、五,告诉你各自的数量,求由这些钱币所不能组成的最小财富这并不是连续的数值,所以在进行表达式的展开时,用的是数组,而不是小标 i 。const int MAX = 1000;const int type3 = 1,2,5

7、;bool ansMAX,tmpMAX;int cnt3;void Search() int i,j,k; /全部初始化为0 memset(ans,0,sizeof(ans); memset(tmp,0,sizeof(tmp); for(i=0;=cnt0;+i) ansi = true; for(i=1;3; for(j=0;=MAX;+j) for(k=0;=cnti & j+k*typeicnt1cnt2) if(cnt0=0 & cnt1=0 & cnt2=0)break; Search(); for(int i=0; if(!ansi) res = i; break;res 5、写出

8、完整的二分查找程序,要求:(1)先将给定的数据利用快速排序进行排序(采用复杂度为nlg(n)的算法)。(2)利用二分查找法判断给定的数据是否在数据集中。快速排序算法:对于包含n个数的输入数组来说,快速排序是一种最坏情况时间复杂度为O(n2)的排序算法,他的平均性能非常好,期望时间复杂度为nlgn.与归并排序一样,快速排序也使用了分治思想:快速排序是找出一个元素(理论上可以随便找一个)作为基准(pivot),然后对数组进行分区操作,使基准左边元素的值都不大于基准值,基准右边的元素值 都不小于基准值,如此作为基准的元素调整到排序后的正确位置。递归快速排序,将其他n-1个元素也调整到排序后的正确位置

9、。最后每个元素都是在排序后的正 确位置,排序完成。所以快速排序算法的核心算法是分区操作,即如何调整基准的位置以及调整返回基准的最终位置以便分治递归。/快速排序void quicksort(int v, int left, int right) if(left right) int key = vleft; int low = left; int high = right; while(low high) while(low key) high-; vlow = vhigh; vlow left) if(amid=p) return p; else if(amidp) right=mid-1;

10、else left=mid+1; mid=(left+right)/2; return -1; void main()/主函数 int x,p; int a18=4,13,8,10,1,6,5,2,18,11,12,9,17,16,3,7,14,15;Pease input the number you want to research:p;排序前的数组:18;ai /b_up(a,18); quicksort(a,0,17);排序后的数组: x=search(a,18,p); if(x=-1)The number can not be found!The number:xwas found!

11、【一般不会考】6、Problem DescriptionYou are given a number of case-sensitive strings of alphabetic characters, find the largest string X, such that either X, or its inverse can be found as a substring of any of the given strings.The first line of the input file contains a single integer t (1 = t = 10), the

12、number of test cases, followed by the input data for each test case. The first line of each test case contains a single integer n (1 = n =0;i-) revstot+=swi; revstot=0int Find(int p) int lens=strlen(st),rlens=strlen(st),i,j; bool flag; while(lens)/从最长的开始找 =rlens-lens;i+) strncpy(vs,st+i,lens); strnc

13、py(revs,st+i,lens);/第二个复制,用于下面的倒置 vslens=revslens=/尾问处理 strev();/没有参数,但每次调用的作用都是倒置revs flag=true;Np;j+)/比较全部字符串 strstr(strj,revs)&!strstr(strj,vs) flag=false; if(flag) return lens; lens-; return lens;/可能一个也没有,返回0 /主函数 int caseNumber,i,x=110;caseNumber; int t=caseNumber; while(t-) Nt; x=110; FOR(i,Nt) stri; if(strlen(stri)x)/寻找最短的字符串 x=strlen(stri); strcpy(st,stri); FOR(i,caseNumber)coutFind(i)

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1