无题

本文解析了微软2017年的四道面试题,包括传奇物品获取的数学期望、树结构恢复、迷宫中消灭怪物的策略及括号序列的完善方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

微软2017年招聘题目:






题目1 : Legendary Items

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

描述

Little Hi is playing a video game. Each time he accomplishes a quest in the game, Little Hi has a chance to get a legendary item.

At the beginning the probability is P%. Each time Little Hi accomplishes a quest without getting a legendary item, the probability will go up Q%. Since the probability is getting higher he will get a legendary item eventually.

After getting a legendary item the probability will be reset to ⌊P/(2I)⌋% (⌊x⌋ represents the largest integer no more than x) where I is the number of legendary items he already has. The probability will also go up Q% each time Little Hi accomplishes a quest until he gets another legendary item.

Now Little Hi wants to know the expected number of quests he has to accomplish to get N legendary items.  

Assume P = 50, Q = 75 and N = 2, as the below figure shows the expected number of quests is

2*50%*25% + 3*50%*75%*100% + 3*50%*100%*25% + 4*50%*100%*75%*100% = 3.25

输入

The first line contains three integers PQ and N.  

1 ≤ N ≤ 106, 0 ≤ P ≤ 100, 1 ≤ Q ≤ 100

输出

Output the expected number of quests rounded to 2 decimal places.

样例输入
50 75 2
样例输出 3.25




题目2 : Tree Restoration

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

描述

There is a tree of N nodes which are numbered from 1 to N. Unfortunately, its edges are missing so we don't know how the nodes are connected. Instead we know:  

1. Which nodes are leaves  

2. The distance (number of edges) between any pair of leaves

3. The depth of every node (the root's depth is 1)

4. For the nodes on the same level, their order from left to right

Can you restore the tree's edges with these information? Note if node u is on the left of node vu's parent should not be on the right of v's parent.


输入

The first line contains three integers NM and KN is the number of nodes. M is the depth of the tree. K is the number of leaves.

The second line contains M integers A1, A2, ... AMAi represents the number of nodes of depth i.

Then M lines follow. The ith of the M lines contains Ai numbers which are the nodes of depth i from left to right.  

The (M+3)-th line contains K numbers L1, L2, ... LK, indicating the leaves.

Then a K × K matrix D follows. Dij represents the distance between Li and Lj.

1 ≤ N ≤ 100

输出

For every node from 1 to N output its parent. Output 0 for the root's parent.

样例输入
8 3 5  
1 3 4  
1  
2 3 4  
5 6 7 8  
3 5 6 7 8  
0 3 3 3 3  
3 0 2 4 4  
3 2 0 4 4  
3 4 4 0 2  
3 4 4 2 0
样例输出
0 1 1 1 2 2 4 4




题目3 : Monster Killing

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

描述

In a video game Little Hi is trapped in a maze. The maze can be considered as an N × M grid. There are monsters on some cells. Each cell has one monster at most. Below is an example of a 4x5 maze. '.' represents an empty cell. 'D' represents the entrance, Little Hi's starting point. 'M' represents a normal monster. 'S' represents a special monster.  

..S..
M...M
..D..
.M...

At the beginning, each cell is covered by a slate except that the slate on the entrance cell has been already removed. Each round Little Hi may either remove a slate as long as

1. each monster has either been killed or still covered by a slate, and

2. the cell covered by the slate is adjacent to some cell whose slate has been already removed. (Two cells are adjacent if they share a common side.)

or attack a monster as long as the slate covering it has been removed.

At the beginning Little Hi has Hp hit points and Ap attack points. Each monster also has its hit points Hi and attack points Ai. When Little Hi attacks a monster, the hit points of both sides should subtract the attack points of the other side.

For example, if Little Hi's hit points are 50 and attack points are 30. When he attacks a monster whose hit points are 25 and attack points are 10, the remaining hit points for Little Hi are 40 and the remaining hit points for the monster are -5.

When hit points are less than or equal to 0 the monster is killed.

At the beginning Little Hi has a buff called "Destruction Blade" which lasts for 5 rounds. With such buff Little Hi does not take damage when he attacks a monster. The buff vanishes after 5 rounds but can be refreshed or regained for the following 5 rounds after killing a special monster. (Note that the buff always lasts for 5 rounds after killing a special monster no matter how many rounds left before killing the monster.)

Now given the map of the maze. Can you tell whether Little Hi can kill all the monsters? If he can what is the maximum remaining hit points?

输入

Line 1: two integers N and M. (2 ≤ NM ≤ 6, N × M ≤ 20)

Line 2 .. N+1: M characters per line, representing the maze map.

Line N+2 .. N+K+1: two integers Hi and Ai per line, representing the hit points and attack points for each monster, from top to bottom and left to right. (3 ≤ K ≤ 7)

Line N+K+2: two integers Hp and Ap, the hit points and attack points for Little Hi.

输出

If Little Hi can kill all the monsters and stay alive output the maximum remaining hit points. Otherwise output DEAD.

样例解释

Let's assume the upper left cell is (1, 1).

Round 1: remove slate (2, 3), buff remains 4 rounds

Round 2: remove slate (2, 2), buff remains 3 rounds

Round 3: remove slate (2, 1), buff remains 2 rounds

Round 4: attack monster (2, 1), take no damage, buff remains 1 round

Round 5: attack monster (2, 1), take no damage, monster killed, buff vanishes

Round 6: remove slate (2, 4)  

Round 7: remove slate (4, 3)  

Round 8: remove slate (1, 3)  

Round 9: attack monster (1, 3), take 5 damage, HP=55

Round 10: attack monster (1, 3), take 5 damage, HP=50, monster killed, buff remains 5 rounds

Round 11: remove slate (2, 5), buff remains 4 rounds

Round 12: attack monster (2, 5) take no damage, buff remains 3 rounds

Round 13: attack monster (2, 5) take no damage, buff remains 2 rounds

Round 14: remove slate (4, 2), buff remains 1 round

Round 15: attack monster (4, 2), take no damage, buff vanishes

Round 16: attack monster (4, 2), take 5 damage, HP=45, monster killed

样例输入
4 5  
..S..  
M...M  
..D..  
.M...  
20 5  
20 5  
20 5  
20 5  
60 10
样例输出
45






题目4 : Parentheses Sequence

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

描述

You are given a sequence S of parentheses. You are asked to insert into S as few parentheses as possible so that the resulting sequence T is well matched.

It's not difficult. But can you tell how many different T you can get?

Assume S = ()), you can get either (()) or ()().

输入

One line contains the sequence S.  

For 30% of the data, 1 ≤ |S| ≤ 10  

For 60% of the data, 1 ≤ |S| ≤ 200  

For 100% of the data, 1 ≤ |S| ≤ 1000  

输出

Output 2 integers indicating the minimum number of parentheses need to be inserted into S and the number of different T. The number of different T may be very large, so output the answer modulo 109+7.

样例输入
())
样例输出
1 2

思路:A 概率题

可以发现第一件物品的获得和第二件物品的获得是独立事件。所以N件物品的总期望步数就是每一件的期望步数之和。

而每一件物品最多失败100次,所以可以直接算。

B 模拟题

其实就是模拟手算过程,考察代码能力。 可以想想拿到样例手算是怎么算的。

基本思路就是自底向上递推。 
5在最左边,所以5的父节点肯定是2。 
6和5的距离是2,所以5和6肯定有公共父节点。于是6的父节点也是2。 
7和6的距离大于2,所以7和6肯定没有公共父节点。于是7的父节点是4(3是叶子结点,所以不会是7的父节点)。 
8和7距离是2,所以8的父节点也是4。

同理一层一层向上推就行了。

这题数据范围非常小,节点数只有100。所以可以各种暴力做...

C 搜索

数据范围很小,暴搜+最优化剪枝就行。

D DP

有点类似整数划分的动态规划。


OpenCV(Open Source Computer Vision Library)是一个开源的计算机视觉和机器学习软件库,广泛应用于图像处理、计算机视觉和模式识别等领域。物体识别是OpenCV的一个重要应用场景,以下是一些常见的物体识别方法和技术: 1. **特征提取与匹配**: - **SIFT(尺度不变特征变换)**和**SURF(加速稳健特征)**:这些算法用于检测和描述局部特征,能够在图像中识别出相同的物体,即使它们的大小、旋转或光照条件发生变化。 - **ORB(定向快速旋转BRIEF)**:一种快速的特征检测和描述算法,适用于实时应用。 2. **模板匹配**: - 通过在图像中滑动一个模板(已知物体的图像),并计算模板与图像区域的相似度,来找到物体的位置。 3. **机器学习与深度学习**: - **支持向量机(SVM)**:用于分类和回归分析,可以用于物体识别任务。 - **卷积神经网络(CNN)**:深度学习模型,特别适合处理图像数据,能够自动学习图像的特征并进行分类。 4. **目标检测算法**: - **Haar级联分类器**:基于积分图和AdaBoost算法,用于实时人脸检测。 - **YOLO(You Only Look Once)**和**SSD(Single Shot MultiBox Detector)**:实时目标检测算法,能够在单次前向传播中同时进行目标定位和分类。 5. **实例分割**: - **Mask R-CNN**:在目标检测的基础上,进一步分割出目标的精确轮廓。 OpenCV提供了丰富的API和工具,可以方便地实现上述方法。以下是一个简单的示例代码,展示如何使用OpenCV进行模板匹配: ```python import cv2 import numpy as np # 读取原始图像和模板图像 original_image = cv2.imread('original_image.jpg') template = cv2.imread('template.jpg') template_gray = cv2.cvtColor(template, cv2.COLOR_BGR2GRAY) w, h = template_gray.shape[::-1] # 转换为灰度图 gray_original = cv2.cvtColor(original_image, cv2.COLOR_BGR2GRAY) # 模板匹配 result = cv2.matchTemplate(gray_original, template_gray, cv2.TM_CCOEFF_NORMED) threshold = 0.8 loc = np.where(result >= threshold) # 绘制矩形框 for pt in zip(*loc[::-1]): cv2.rectangle(original_image, pt, (pt[0] + w, pt[1] + h), (0, 255, 255), 2) # 显示结果 cv2.imshow('Detected', original_image) cv2.waitKey(0) cv2.destroyAllWindows() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值