![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
笔试编程题
cainiaoxiaomin
这个作者很懒,什么都没留下…
展开
-
华为机试 地铁换乘问题(最短路径算法)
1.题目描述 描述: 已知2条地铁线路,其中A为环线,B为东西向线路,线路都是双向的。经过的站点名分别如下,两条线交叉的换乘点用T1、T2表示。编写程序,任意输入两个站点名称,输出乘坐地铁最少需要经过的车站数量(含输入的起点和终点,换乘站点只计算一次)。 地铁线A(环线)经过车站:A1 A2 A3 A4 A5 A6 A7 A8 A9 T1 A10 A11 A12 A1原创 2015-08-05 20:19:02 · 1677 阅读 · 0 评论 -
leetcode题目 合并N个排序好的链表
题目: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 思路: 两种方法,第一种思路调用合并两个排序好链表的函数,时间效率O(kN),k是链表个数,N是所有链表节点总数。第二种思路采用一个最小堆,先将k的链表的头结点构造成一个最小堆,取出最小的元素原创 2015-10-03 23:03:26 · 1048 阅读 · 0 评论 -
leetcode题目 寻找和为SUM的两数(O(nlogn)和O(n)解法)
leetcode第一题 题目: Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the原创 2015-10-04 16:27:39 · 593 阅读 · 0 评论 -
leetcode题目 二分查找升级版
题目: Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm’s runtime complexity must be in the order of O(log n).If the target is not found in th原创 2015-10-05 22:30:49 · 755 阅读 · 0 评论 -
leetcode题目 寻找和为SUM的集合系列问题
题目一: Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeated number may be chosen from C unlimited numbe原创 2015-10-06 16:35:56 · 362 阅读 · 0 评论 -
leetcode题目 丢失的第一个正数
题目: Given an unsorted integer array, find the first missing positive integer. For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2. Your algorithm should run in O(n) time and uses constant原创 2015-10-06 18:35:18 · 575 阅读 · 0 评论 -
leetcode题目 全排列(三种解法)
题目: Given a collection of numbers, return all possible permutations. For example, [1,2,3] have the following permutations: [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1]. 思路: 全排列的问题解法很多,本文列原创 2015-10-07 21:32:57 · 923 阅读 · 0 评论 -
leetcode题目 聚合相同的字母组成的单词
题目: Given an array of strings, group anagrams together. For example, given: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”], Return: [ [“ate”, “eat”,”tea”], [“nat”,”tan”], [“bat”] ] Note:1.F原创 2015-10-07 22:23:46 · 700 阅读 · 0 评论 -
leetcode题目 跳跃游戏系列题目
题目: Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Your goal is t原创 2015-10-06 23:27:20 · 657 阅读 · 0 评论 -
MaxGap leetcode题目(桶排序)
Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2 elements.You may原创 2015-09-21 11:14:39 · 575 阅读 · 0 评论 -
leetcode题目 旋转排序数列的查找
题目: Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array return its i原创 2015-10-05 18:03:58 · 352 阅读 · 0 评论 -
leetcode题目 反转链表系列问题
题目1: Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only constant space. Yo原创 2015-10-04 22:19:29 · 405 阅读 · 0 评论 -
360笔试编程题 找老乡(并查集解法)
题目:大学的同学来自全国各地,对于远离家乡步入陌生大学校园的大一新生来说,碰到老乡是多么激动的一件事,于是大家都热衷于问身边的同学是否与自己同乡。来自新疆的小鲵尤其热衷。但是大家都不告诉小尼他们来自哪里,只是说与谁同乡。从所给的信息中,你能告诉小尼有多少人确定是她的同乡么? 输入:每个测试实例首先包括两个整数,N(1 = < N < = 1000),M(0 = < M < = N*(N-1)/原创 2015-09-30 18:22:16 · 1870 阅读 · 0 评论 -
华为机试 是否存在路径(深度优先遍历、回朔法、递归)
题目:输入一个矩阵以及其行列值,矩阵中‘-’表示可以移动的坐标,‘#’表示障碍物不可以通过,‘B’表示起点,‘H’表示终点。在矩阵中可以上下左右移动,不可以斜线移动,求问是否存在从起点B到终点H的路径。 例如输入:3 3B - -# # -- H -则应该输出YES题目分析:题目是图论遍历问题,可以采用深度优先遍历的方法进行路径查找。采用回朔法、递归的思路解决问题。代码如下。原创 2015-08-14 22:50:41 · 683 阅读 · 0 评论 -
华为机试 黑白棋子最佳匹配(全排列)
题目:棋盘上有黑白两种颜色的棋子,选出一对黑白棋子,若白棋的横坐标小于黑棋的横坐标,白棋的纵坐标小于黑棋的纵坐标,则称这一对棋子为匹配。求任意个数的黑白棋中最佳匹配的对数。 输入:白棋个数,黑棋个数 白棋的横纵坐标 黑棋的横纵坐标 例如:2 21 1 2 21 1 2 2则输出为1 分析:可以对黑白棋中个数较多的一方进行全排列,然后进行比较,找出最大匹配度。若黑白棋的个数均为n,则问题原创 2015-08-15 15:15:47 · 1563 阅读 · 0 评论 -
华为机试 单词查找、排序、去重
题目:在给定字符串中找出单词( “单词”由大写字母和小写字母字符构成,其他非字母字符视为单词的间隔,如空格、问号、数字等等;另外单个字母不算单词);找到单词后,按照长度进行降序排序,(排序时如果长度相同,则按出现的顺序进行排列),然后输出到一个新的字符串中;如果某个单词重复出现多次,则只输出一次;如果整个输入的字符串中没有找到单词,请输出空串。输出的单词之间使用一个“空格”隔开,最后一个单词后不加空原创 2015-08-05 22:10:45 · 1004 阅读 · 0 评论 -
阿里15实习生招聘笔试 字符保序输出问题
题目:分布式系统中的RPC请求经常出现乱序的情况。写一个算法来将一个乱序的序列保序输出。例如,假设起始序号是1,对于(1, 2, 5, 8, 10, 4, 3, 6, 9, 7)这个序列,输出是:123, 4, 567, 8, 9, 10 上述例子中,3到来的时候会发现4,5已经在了。因此将已经满足顺序的整个序列(3, 4, 5)输出为一行。 要求:原创 2015-04-03 10:36:43 · 487 阅读 · 0 评论 -
腾讯15笔试 爸爸去哪站队问题
题目:爸爸去哪中的三对父子站成一排,各自父子之间不能相邻,比如石头不能相邻郭涛挨着,以此类推共有多少种站法。 选项120,48,240,144#include <vector>#include <iostream>#include <string>#include <algorithm>using namespace std;int main(int argv, char** argc){原创 2015-09-06 09:23:26 · 695 阅读 · 1 评论 -
搜狗16招聘机试题 加密解密算法
题目:下面程序中,shuffle函数用于把整数数列打散,函数参数seed是一个随机种子,同一个随机种子产生一个确定的随机序列。请为shuffle写一个还原函数(restore)。其输入是经过shuffle打散的整数数列a[]以及打散时使用的随机种子seed,功能时将a[]数列还原为打散前的内容。 注意:本题要求额外空间开销越小越好,时间复杂度相对不重要。 输入:seed N 数值1 数值2 ….原创 2015-09-26 16:33:50 · 348 阅读 · 0 评论 -
华为机试 寻找最大正方形
给你一个N*M矩阵,每个位置的值是0或1,求一个面积最大的子矩阵,这个矩阵必须是一个正方形,且里面只能由1构成,输出最大正方形边长。 输入:第一行输入两个正整数n,m,之后n行,每行m个数组,为矩阵第i行第j列的值,只可能是0或1。n,m<=400。 输出:一个整数,为最大正方形的边长 样例输入: 3 3 1 1 1 1 1 1 0 0 1 样例输出:2#include <iost原创 2015-09-12 14:57:05 · 2639 阅读 · 0 评论 -
微软笔试编程题 求多少个子序列符合斐波那契排列
描述 Given a sequence {an}, how many non-empty sub-sequence of it is a prefix of fibonacci sequence.A sub-sequence is a sequence that can be derived from another sequence by deleting some elements witho原创 2015-09-29 23:00:58 · 580 阅读 · 0 评论 -
360笔试编程题 找老乡(BFS解法)
题目:大学的同学来自全国各地,对于远离家乡步入陌生大学校园的大一新生来说,碰到老乡是多么激动的一件事,于是大家都热衷于问身边的同学是否与自己同乡。来自新疆的小鲵尤其热衷。但是大家都不告诉小尼他们来自哪里,只是说与谁同乡。从所给的信息中,你能告诉小尼有多少人确定是她的同乡么? 输入:每个测试实例首先包括两个整数,N(1 = < N < = 1000),M(0 = < M < = N*(N-1)/2)原创 2015-09-30 11:10:50 · 1379 阅读 · 0 评论 -
喷水装置 ACM题目 京东16招聘编程题(贪心算法)
描述:现有一块草坪,长为20米,宽为2米,要在横中心线上放置半径为Ri的喷水装置,每个喷水装置的效果都会让以它为中心的半径为实数Ri(0 < Ri < 15)的圆被湿润,这有充足的喷水装置i(1 < i < 600)个,并且一定能把草坪全部湿润,你要做的是:选择尽量少的喷水装置,把整个草坪的全部湿润。 输入:第一行m表示有m组测试数据 每一组测试数据的第一行有一个整数数n,n表示共有n个喷水装置原创 2015-09-24 11:20:01 · 559 阅读 · 0 评论