Several algorithms for written tests __ algorithm

Source: Internet
Author: User

Yesterday mobile phone update wp8.1 into a brick, to take to HTC after the sale of the motherboard (HTC after the sale of very good OH), get back and then upgrade. Received a giant network of written notice, to go to Shanghai, no matter go, do some algorithm first to say it, find some basic questions put up:

1. Write a function, exchange the value of two variables, do not use the third variable.


2. Suppose a up stairs, can cross 1, 2 or 3 layers at a time, ask a up to 50 steps, how many kinds of walk method.
Assuming a up-stairs, it can span 1, 2, 3 layers at a time. or M layer, ask a on the N-level steps, how many ways to go.
where M and n are all positive integers, and M <= N, M <=, N <= 50
Please program to solve this problem, and explain the idea of solving problems in detail.


3. Please design a set of algorithms for all n-character permutations.
If the algorithm outputs a full order sequence, the number is labeled separately, from 1 to n!
So, given the low, high, can not calculate all permutations, and directly output the low to the first high of the arrangement.
Please write the sample code and explain the idea of the problem in detail.


4. A building has n-storey, to go to each level of the number of p[1], p[2], ..., p[n], if the elevator only stop 1 times, ask to stop which floor, you can let everyone walk the least.
If the energy consumption on the road floor is K1, the energy consumed by the next floor is K2, and the energy consumed by the elevator on the floor is K3, ask which layer to stop, which will let everyone consume the least energy.
Please program to solve this problem, and explain the idea of solving problems in detail.

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.