Microsoft Research Asia 2017 written test Programming questions _ Microsoft Research Asia

Source: Internet
Author: User
Tags rounds

1. Programming Question 1

Little Hi is playing a video game.

Accomplishes a quest in the game and 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'll go up q%.

Since the probability is getting higher he'll get a legendary item eventually. After getting a legendary item the probability is reset to? p/(2I)?% (? x represents the largest integer no more than x) where I was the number of legendary items he already has.

The probability would also go up q% each time Little Hi accomplishes a quest until he gets another item.  

Now Little Hi wants to know the expected number of quests him has to accomplish to get N legendary items. Assume P = 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 Legendary.png Enter the "I" contains three P, Q and N.  

1≤n≤106, 0≤p≤100, 1≤q≤100 output The expected number of quests rounded to 2 decimal places. Example input 50 75 2 sample output 3.25 Emacsnormalvim

2. Programming Question 2

"There is a"-n nodes which are numbered from 1 to N. Unfortunately, it edges are missing so we don ' t know nodes are connected. Instead We know:

Which nodes are leaves

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

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

For the "nodes on" same level their

Can you restore the tree ' s edges with these information? Note If node you are on the left of Node V, U ' s parent should not being on the right of V ' s parent.

Tree-restoration.png

Input
The 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 kxk matrix D follows. Dij represents the distance between Li and Lj.

1≤n≤100

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

Sample input
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
Sample output
0 1 1 1 2 2 4 4 '

 3. Programming title 3*** ' "In a" game Little Hi is trapped in a maze. The maze can is considered as an NXM 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, where the covered by a slate except to the slate on the entrance cell has been already. 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 are adjacent to some cell whose slate has been already.

(two cells are adjacent if they share a common side.)

Or attack a monster as long as the slate covering it has been. 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 to should subtract the attack the other points. For example, if Little Hi ' s hit points are attack and points are 30. When he attacks a monster whose hit points are and attack points are, 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 blades" which lasts for 5 rounds. With the such buff Little Hi does not take damage as he attacks a monster. The buff vanishes after 5 rounds but can is refreshed or regained for the following 5 rounds after killing a special monst Er. (Note this buff always lasts for 5 rounds after killing a special monster no matter how many rounds left before

G The monster.) Now given the map of the maze. can tell whether Little Hi can kill all the monsters? If He can what is the maximum remaining hit PoinTs? Enter line 1:two integers N and M. (2≤n, m≤6, nxm≤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 for each points and left to right.

(3≤k≤7)

Line n+k+2:two integers Hp and Ap, the hit points and attack for points Hi. Output If Little Hi can kill all the monsters and stay alive output the maximum remaining.

Otherwise output DEAD.

Examples explain 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 (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:remo ve Slate (2, 5), Buff remains 4 rounds Round 12:attack Monster (2, 5) take no damage, buff remains 3 rounds Round, 13:a  Ttack Monster (2, 5) take no damage, buff remains 2 rounds Round 14:remove (4, 2), Slate buff 1 remains Round 15: Attack Monster (4, 2), take no damage buff vanishes Round 16:attack monster (4, 2), take 5 damage, hp=45, Monster Kill Ed Sample input 4 5. S.. M.. M.. D...  
M...
 20 5 20 5 20 5 20 5 60 10 Example output <div class= "Se-preview-section-delimiter" ></div>

4. Programming Question 4

Here to write the code piece

 4. Programming Questions 4***

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

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

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

Input
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
Output 2 integers indicating the minimum number of parentheses need to is inserted into S and the number of different T. T He number of different T is very large, so output the answer modulo 109+7.

Sample input
())
Sample output
1 2
"'

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.