微软笔试题目

如下三道题:

题目2 : Composition

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

Alice writes an English composition with a length of N characters. However, her teacher requires that M illegal pairs of characters cannot be adjacent, and if 'ab' cannot be adjacent, 'ba' cannot be adjacent either.

In order to meet the requirements, Alice needs to delete some characters.

Please work out the minimum number of characters that need to be deleted.

输入

The first line contains the length of the composition N.

The second line contains N characters, which make up the composition. Each character belongs to 'a'..'z'.

The third line contains the number of illegal pairs M.

Each of the next M lines contains two characters ch1 and ch2,which cannot be adjacent.  

For 20% of the data: 1 ≤ N ≤ 10

For 50% of the data: 1 ≤ N ≤ 1000  

For 100% of the data: 1 ≤ N ≤ 100000, M ≤ 200.

输出

One line with an integer indicating the minimum number of characters that need to be deleted.

样例提示

Delete 'a' and 'd'.

样例输入
5
abcde
3
ac
ab
de
样例输出
2

题目3 : Registration Day

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

It's H University's Registration Day for new students. There are M offices in H University, numbered from 1 to M. Students need to visit some of them in a certain order to finish their registration procedures. The offices are in different places. So it takes K units of time to move from one office to another.

There is only one teacher in each office. It takes him/her some time to finish one student's procedure. For different students this time may vary. At the same time the teacher can only serve one student so some students may need to wait outside until the teacher is available. Students who arrived at the office earlier will be served earlier. If multiple students arrived at the same time they will be served in ascending order by student number .

N new students need to finish his/her registration. They are numbered from 1 to N. The ith student's student number is Si. He will be arrived at H University's gate at time Ti. He needs to visit Pi offices in sequence which are Oi,1, Oi,2, ... Oi,Pi. It takes him Wi,1, Wi,2, ... Wi,Pi units of time to finish the procedure in respective offices. It also takes him K units of time to move from the gate to the first office.

For each student can you tell when his registration will be finished?

输入

The first line contains 3 integers, N, M and K.  (1 <= N <= 10000, 1 <= M <= 100, 1 <= K <= 1000)

The following N lines each describe a student.

For each line the first three integers are Si, Ti and Pi. Then following Pi pairs of integers: Oi,1, Wi,1, Oi,2, Wi,2, ... Oi,Pi, Wi,Pi. (1 <= Si <= 2000000000, 1 <= Ti <= 10000, 1 <= Pi <= M, 1 <= Oi,j <= M, 1 <= Wi,j <= 1000)

输出

For each student output the time when he finished the registration.

样例提示

Student 1600012345 will be arrived at the gate at time 500. He needs to first visit Office #1 and then Office #2. He will be arrived at office #1 at time 600. He will leave office #1 at time 1100. Then He will arrive at office #2 at 1200. At the same time another student arrives at the same office too. His student number is smaller so he will be served first. He leaves Office #2 at 1700. End of registration.

Student 1600054321 will be arrived at the gate at time 1100. He will be arrived at Office #2 at 1200. Another student with smaller student number will be served first so he waits for his turn until 1700. He leaves Office #2 at 2000. End of registration.

样例输入
2 2 100  
1600012345 500 2 1 500 2 500  
1600054321 1100 1 2 300
样例输出
1700  
2000

题目4 : MS Recognition

时间限制:30000ms
单点时限:3000ms
内存限制:256MB

描述

Given an image containing only two kinds of capital letters, 'M' and 'S', can you tell how many of each letter are there in the image? Note that the letters may be of different sizes and may be rotated.

输入

The first line contains two integers H and W, indicating the height and weight of the image.  (1 <= H, W <= 500)  

Then follows an H x W matrix indicating the image.

'.' indicates the pixel is empty and '#' indicates the pixel is part of a letter.  

It is guaranteed that:  

1. The letters are actually in Microsoft Yahei font.  

2. Each letter consists of at least 20 pixels.  

3. Different letters are at least 2 pixels away from each other.

输出

Two integers, the number of 'M' letters and the number of 'S' letters.

样例输入
50 50
..................................................
..................................................
..........................................#.......
............................###..........##.......
.......##..................##.##........#.........
.......##..................#...........##.........
......###.......#..........#...........##.........
......####.....###.........###..........######....
......#.##.....###..........####..............#...
......#.##....####............##..............#...
.....##..#...##.#..........#...#.............##...
.....##..#..##.##..........#####...........##.....
.....#...#.##..##.................................
.....#...###...#..................................
.....#...###...#..................................
.........##...##......................##..........
..............##.....##..............###..........
....................###............###............
...................###.............##.............
..................###.............##..............
.................###..............##..............
................###......###.......########.......
...............###.....#####........########......
..............###...########...............##.....
.............###..#####..##................##.....
............########....###................##.....
...........#######......##.....##.........###.....
............###.........##....###.......####......
.......................###...###.......###........
.......#...............##...###...................
.....####.............###..###....................
...######.............##..###.....................
..####................######......................
..###................######.......................
.###.................#####.......##...............
.###................#####........######...........
.###.................###.........##########.......
..##########.......................##...####......
..############......................##............
....###########......................###..........
.............##.......................###.........
.............###.......................###........
.............###...................#######........
.............##................########...........
............###................####...............
..........####..................######............
.......######......................######.........
.......###.............................##.........
..................................................
..................................................
样例输出
3 4


#阿里巴巴##腾讯##google##微软##网易##前端工程师##算法工程师#
全部评论
A了3道,第四题完全没想法。我的第三题AC代码http://hihocoder.com/discuss/question/3968
点赞 回复
分享
发布于 2016-10-10 22:18
看来你第一题做出来了=。=
点赞 回复
分享
发布于 2016-10-10 21:30
阅文集团
校招火热招聘中
官网直投
更新速度好快啊,第二题就想不出来了,自己太渣了
点赞 回复
分享
发布于 2016-10-10 21:45
第二题思路:初始化一个大小为26,全零的int数组,数组中的数字代表以该字母结尾、最长、没有冲突的字符串的长度。下标为0的位置代表以“a”结尾的最大字符串长度,下标为1的位置代表以“b”结尾的最大字符串长度。逐个扫描带处理字符串,更新数组数据,最后得到数组中的最大数字,就可以算出最少需要删除多少个字母
点赞 回复
分享
发布于 2016-10-10 22:17
微软笔试有几场啊?
点赞 回复
分享
发布于 2016-10-10 22:31

相关推荐

2 12 评论
分享
牛客网
牛客企业服务