Microsoft 2017 Foundation program online programming pen test legendary Items

Source: Internet
Author: User
Tags time limit



Title 1:legendary Items time limit: 10000ms single point limit: 1000ms memory limit: 256MB description

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 is 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

Input

The contains three integers P, Q and N.

1≤n≤106, 0≤p≤100, 1≤q≤100 output

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

50 75 2
Sample output
3.25



Read for a long time to understand.


The probability of completing a quest with no legendary item is increased q% (until legendary item is obtained), legendary item quest, and the probability is reset to p/(2^i)%

Reflected in the diagram is: the left node of each node is a solid node (completed legendary item), the right node is an empty node (legendary item is not completed). The left node of each empty node (assuming probability x) is X+q, and the left node probability of the solid node is p/(2^i)%, (the sum of the right and left nodes of each node in the graph is 100%). How much quest is needed to get n a Legendaryitem

The above figure for example, from the top down, p is 50%,n for 2 o'clock, left to go, the probability is: 50%,25% (2 legendary item), then stop

View the entire tree as an n-tier, starting at the bottom.

Here's the calculation: from the bottom up, starting with the leftmost 25% node, this is 0.25* (0+1), and you don't have to go down (because you've got 2 legendary item)

The right node is 1-0.25=0.75 (former), downward continuation probability is 0.25+q=1 (if less than 1, can go down), the probability is 0.75* (0+2). The sum of the two points and 0.25+0.75*2=1.75

The parent node of 25% is 50%, then 50% is 0.5* (1.75+1), meaning that the child node of this point plus 1 level multiplied by 0.5 is this point value

Look at the other 50% (right node), former 0.5, continue down to 0.5* (1.75+2), two points and 3.25




AC Code:

public class Main {public
	static void Main (string[] args) {
        Scanner in = new Scanner (system.in);
        int p = in.nextint ();
    	int q = In.nextint ();
    	int n = in.nextint ();
    	Helper (p, q, N);
	}
	public static void helper (int p, int q, int n) {
		list<integer> List = new arraylist<integer> ();
    	List.add (p);
    	Double r = 0;
    	for (int i = 1; i < n; i++) {
    		list.add (list.get (i-1)/2);
    	}
    	for (int m = n-1 m >= 0; m--) {
    		int tmp = List.get (m);
    		Double one = 0, former = 1;
    		int level = 1;
    		for (int j = tmp;; j+= q) {
    			if (J >) {
    				j = n;
    			}
    			One + + former * (double) j/100 * (r + level);
    			Former *= (1.0-(double) j/100.0);
  
    			level++;
    			if (j = =) {break
    			    ;
    			}
    		}
    		R = one;
    	}
    	System.out.print (R);
	}


And then recommend a link to explain the written test, the analysis is very good:

Https://github.com/hiho-coder/msft-2017-online-test-solution/blob/master/README.md



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.