微软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
250%25% + 350%75%100% + 350%100%25% + 450%100%75%100% = 3.25

legendary.png
legendary.png

输入
The first line contains three integers P
, Q
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 v
    , u
    's parent should not be on the right of v
    's parent.


    tree-restoration.png
    tree-restoration.png

    输入
    The first line contains three integers N
    , M
    and K
    . N
    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
    , ... AM

. Ai
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 ≤ N, M ≤ 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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,937评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,503评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,712评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,668评论 1 276
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,677评论 5 366
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,601评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,975评论 3 396
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,637评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,881评论 1 298
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,621评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,710评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,387评论 4 319
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,971评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,947评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,189评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 44,805评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,449评论 2 342

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,361评论 0 23
  • 修改虚拟磁盘大小 未分区的情况 未分区且使用卷的情况
    helphi阅读 300评论 0 0
  • 这几天看了Tornado的源码,写这篇文章以做总结。本文采用Tornado v1.2版本的源码,讨论Tornado...
    _heqin阅读 1,141评论 0 1
  • 许梓轩 11月12日 第14次打卡,读了《三国演义》p109~124页,主要讲了:吕布败走下邳城,曹操在白门斩吕布...
    Dream轩阅读 246评论 0 1
  • 2017年,我三十未到,却感觉而立之年的压力。没有女朋友,没有房子,没有金钥匙,没有工作。 作为”四没“人员,我也...
    前山饭店阅读 170评论 2 0