资源预览内容
第1页 / 共13页
第2页 / 共13页
第3页 / 共13页
第4页 / 共13页
第5页 / 共13页
第6页 / 共13页
第7页 / 共13页
第8页 / 共13页
第9页 / 共13页
第10页 / 共13页
亲,该文档总共13页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
2014美团网笔试题目1、一堆硬币,一个机器人,如果是反的就翻正,如果是正的就抛掷一次,无穷多次后,求正反的比例解答:是不是题目不完整啊,我算的是3:12、一个汽车公司的产品,甲厂占40%,乙厂占60%,甲的次品率是1%,乙的次品率是2%,现在抽出一件汽车时次品,问是甲生产的可能性解答:典型的贝叶斯公式,p(甲|废品) = p(甲 & 废品) / p(废品) = (0.4 0.01) /(0.4 0.01 + 0.6 0.02) = 0.253、k链表翻转。给出一个链表和一个数k,比如链表123456,k=2,则翻转后214365,若k=3,翻转后321654,若k=4,翻转后432156,用程序实现非递归可运行代码:#include#include#includetypedefstructnodestructnode*next;intdata;node;voidcreateList(node*head,intdata)node*pre,*cur,*new;pre=NULL;cur=*head;while(cur!=NULL)pre=cur;cur=cur-next;new=(node*)malloc(sizeof(node);new-data=data;new-next=cur;if(pre=NULL)*head=new;elsepre-next=new;voidprintLink(node*head)while(head-next!=NULL)printf(%d,head-data);head=head-next;printf(%dn,head-data);intlinkLen(node*head)intlen=0;while(head!=NULL)len+;head=head-next;returnlen;node*reverseK(node*head,intk)inti,len,time,now;len=linkLen(head);if(lenk)returnhead;elsetime=len/k;node*newhead,*prev,*next,*old,*tail;for(now=0,tail=NULL;nowtime;now+)old=head;for(i=0,prev=NULL;inext;head-next=prev;prev=head;head=next;if(now=0)newhead=prev;old-next=head;if(tail!=NULL)tail-next=prev;tail=old;if(head!=NULL)tail-next=head;returnnewhead;intmain(void)inti,n,k,data;node*head,*newhead;while(scanf(%d%d,&n,&k)!=EOF)for(i=0,head=NULL;in;i+)scanf(%d,&data);createList(&head,data);printLink(head);newhead=reverseK(head,k);printLink(newhead);return0;5、利用两个stack模拟queue剑指offer上的原题,九度oj有专门的练习,这里贴一下我的ac代码:#include#include#includetypedefstructstackinttop;intseq100000;stack;/*入队操作*T=O(1)*/voidpushQueue(stack*s1,intdata)s1-seqs1-top+=data;/*出队操作*T=O(n)*/voidpopQueue(stack*s1,stack*s2)if(s2-top0)printf(%dn,s2-seq-s2-top);elsewhile(s1-top0)s2-seqs2-top+=s1-seq-s1-top;if(s2-top0)printf(%dn,s2-seq-s2-top);elseprintf(-1n);intmain(void)intdata,n;stack*s1,*s2;charstr5;while(scanf(%d,&n)!=EOF)/初始化s1=(stack*)malloc(sizeof(stack);s2=(stack*)malloc(sizeof(stack);s1-top=s2-top=0;while(n-)scanf(%s,str);if(strcmp(str,PUSH)=0)/入队列scanf(%d,&data);pushQueue(s1,data);else/出队列popQueue(s1,s2);free(s1);free(s2);return0;6、一个m*n的矩阵,从左到右从上到下都是递增的,给一个数elem,求是否在矩阵中,给出思路和代码杨氏矩阵,简单题目:#include#include/*有序矩阵查找*T=O(n+n)*/voidfindKey(int*matrix,intn,intm,intkey)introw,col;for(row=0,col=m-1;row=0;)if(matrixrowcol=key)printf(第%d行,第%d列n,row+1,col+1);break;elseif(matrixrowcolkey)col-=1;elserow+=1;printf(不存在!n);intmain(void)inti,j,key,n,m,*matrix;/构造矩阵scanf(%d%d,&n,&m);matrix=(int*)malloc(sizeof(int*)*n);for(i=0;in;i+)matrixi=(int*)malloc(sizeof(int)*m);for(i=0;in;i+)for(
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号