Tsinghua University software 2014 machine test

Source: Internet
Author: User

Tsinghua University software 2014 machine test

by Zhonghuanlin

September 24 2014 Update: September 24 2014

Today just after the machine test, the occupants have not forgotten, I know the note, also is ze Yimeimei it ~ ~ ~

This machine question, relatively speaking, will be more simple, a total of 3 questions, time is 3 hours.

1 Super Lucky number

The topic is roughly descriptive of the narrative:

A number, if it contains only 1 and 4, is the number of lucky numbers, for example, 14,114. But 514 is not the case, because it contains other numbers. If the lucky number is the same as the number 1 and 4, then the super lucky number, such as 14,1144,41 and so on.

The title requires that the input of a n,n range is [1,1e9], the maximum super lucky number of the output [1,n]. Without solution, output-1.

Problem Solving Ideas:

This topic, when n<14, then obviously is no solution, the rest of the situation, at least there are 14, in fact, when the >=14, find a maximum is good, then the largest there is any law, if the input n has x-bit, when the number is odd, the output (x-1)/2 4, and (x-1 )/2 A 1, just fine. If the number of digits is even, then consider some cases, because the output is not greater than N, and the number of 4 and 1 is equal. Also, note that this data 1000, its output should be 41.

Some test data:

In:20 out:14

In:10 out:-1

in:1000 out:41

2 Moving the ball

There are some small balls, 1, 2, ... N
There are two kinds of operations, each naturally

    • 1 x Y, move X to the left of Y
    • 2 x Y, move x to the right of Y

The question is, what is the order of the ball after M operation?

This is actually the case, originally 1,2,3,4,5. (assuming n=5 's words). After 1 1 4 operation, it becomes 2 3 1 4 5

n data range [1,1000]

M data range [1,200000]

Problem Solving Ideas:

A doubly linked list solves the problem. Then use an array to store the positions of these nodes.

Test data:

In:

5, 2 (input is n m)

1 1 4 (indicates operation, 1,x, y)

2 4 2

Out:2 4 3 1 5;

3 Arranging bookshelves

Bookstore Administrator to tidy up the books on the shelves, in fact, is a row of books, so that the book is sorted according to the height of the book, each book has a weight, the greater the weight, the more laborious mobile book, the more tired, let us ask is, the total mobile book The minimum weight is how much.

The data given are:

5 (number of books)

1 2 5 3 3 (indicates the height of the book)

1 1 3 1 1 (weight of the book)

The output is 2,

Why is 2, because here only need to move 4th, 5th book to the third book in front of the line, the order of the guarantee, moving the weight and is 2.

Problem Solving Ideas:

Moving the weight and the smallest, in fact, is to ask, do not move the weight and the maximum is how much. So how do you ask not to move the maximum weight and what? The fact is to record the location of each book, height, weight, and then according to the height of the order, after sorting, according to the position of the node, to find a maximum sub-sequence, but the largest sub-sequence, not the length, but the weight and on, so that the maximum sub-sequence of weight and, is not moving the maximum weight and The total weight minus it, that's the answer we need.

Tsinghua University software 2014 machine test

Related Article

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.