美团网2014年校园招聘笔试题(哈工大)
来源:互联网 发布:淘宝助理教学视频 编辑:程序博客网 时间:2024/05/01 18:38
2014年美团网校园招聘研发类笔试
1、一堆硬币,一个机器人,如果是反的就翻正,如果是正的就抛掷一次,无穷多次后,求正反的比例
设正比例为x,反的比例就是1-x;现在根据反的翻正,正的重新投掷,那么正的就为1-x+(1/2*x),反的就为1/2*x.无穷次会达到平衡,那么1-x就应该等于1/2*x。所以x为2/3,即正的为2/3
4、链表翻转。给出一个链表和一个数k,比如链表1→2→3→4→5→6,k=2,则翻转后2→1→4→3→6→5,若k=3,翻转后3→2→1→6→5→4,若k=4,翻转后4→3→2→1→5→6,用程序实现
#include <iostream>using namespace std;struct ListNode{int m_nValue;ListNode *m_pNext;};ListNode* CreateList(int val){ListNode *pHead = new ListNode;pHead->m_nValue = val;pHead->m_pNext = NULL;return pHead;}void InsertNode(ListNode **pHead, int val){ListNode *pNode = new ListNode;pNode->m_nValue = val;pNode->m_pNext = NULL;while ((*pHead)->m_pNext != NULL){(*pHead) = (*pHead)->m_pNext;}(*pHead)->m_pNext = pNode;(*pHead) = pNode;}void PrintList(ListNode *pHead){while (pHead != NULL){cout<<pHead->m_nValue<<" ";pHead = pHead->m_pNext;}cout<<endl;}ListNode* Reverse(ListNode *pHead){if (pHead == NULL || pHead->m_pNext == NULL){return pHead;}ListNode *pPre = NULL;ListNode *pCurrent = pHead;ListNode *pPost = pHead->m_pNext;while (pCurrent->m_pNext != NULL){pCurrent->m_pNext = pPre;pPre = pCurrent;pCurrent = pPost;pPost = pPost->m_pNext;}pCurrent->m_pNext = pPre;return pCurrent;}ListNode* ReverseList(ListNode *pHead, int k){if (pHead==NULL || pHead->m_pNext==NULL){return pHead;}ListNode *pPre = NULL;ListNode *pCurrent = pHead;ListNode *pPost = pHead->m_pNext;ListNode *pStart = NULL;ListNode *pEnd = NULL;int n = 0;pEnd = pCurrent;pEnd->m_pNext = NULL;while (pPost != NULL){++n;if (n == (k+1)){pStart = pPre;pEnd->m_pNext = ReverseList(pCurrent, k);return pStart;}else{pCurrent->m_pNext = pPre;pPre = pCurrent;pCurrent = pPost;pPost = pPost->m_pNext;}}pCurrent->m_pNext = pPre;pStart = Reverse(pCurrent);return pStart;}int main(){ListNode *pHead = NULL;ListNode *head = NULL;int n;cout<<"输入链表中节点的个数 n:"<<endl;cin>>n;cout<<"请输入n个整数值:"<<endl;for (int i=0; i<n; ++i){int data;cin>>data;if (pHead == NULL){pHead = CreateList(data);head = pHead;}else{InsertNode(&pHead, data);}}int k;cout<<"请输入k:"<<endl;cin>>k;head = ReverseList(head, k);PrintList(head);system("pause");return 0;}
- 美团网2014年校园招聘笔试题(哈工大)
- IGT 2014年校园招聘笔试题
- 美团网2014校园招聘笔试题(长沙站)
- 美团网2014校园招聘笔试题(长沙站)
- 2014校园招聘笔试题
- 校园招聘笔试题
- 校园招聘(笔试)
- 2014年创新工场校园招聘笔试题及答案
- 2014年腾讯,百度,微软等校园招聘笔试题...
- 阿里巴巴2014年校园招聘武汉站笔试题
- 2014年腾讯软件开发校园招聘笔试题
- 阿里巴巴集团2014年校园招聘北京笔试题分析
- 2014年360校园招聘笔试题,干货分享
- 优酷土豆2014年校园招聘会笔试题
- 小米2014年校园招聘笔试题目(排队问题)
- 软件测试工程师-meitu(2014年校园招聘笔试)
- 阿里巴巴2014校园招聘笔试题(华科)
- 百度2014校园招聘笔试题(武汉站 9.28)
- mongoDB——自动分片介绍及简单实现
- org.apache.hadoop.security.AccessControlException: Permission denied: user=xxj, acces
- 婴儿常见问题总结
- 组件映射配置
- 迅雷校园面试题
- 美团网2014年校园招聘笔试题(哈工大)
- CSS样式命名整理
- 学习笔记-XML基础
- 初学 Java 很多不懂:常用功能代码
- linux进程状态
- JAVA学习--GridLayout
- AJAX 跨域请求 - JSONP获取JSON数据
- Linux 防火墙策略
- 跨平台日志清理工具 Log-Cutter v1.0.3 正式发布