NetEase 2017 Spring recruit written test real problem programming problem collection--python

Source: Internet
Author: User
Tags benchmark

Note: The pen question is excerpted from the cow net, altogether 12 programming questions. The following include topic descriptions, personal thinking, correct results
1. The two cores of a dual-core CPU are capable of simultaneous processing tasks, and now there are n tasks with a known amount of data to be handed over to the CPU, assuming that each core of the known CPU can handle 1KB, and each core can handle only one task at a time. n tasks can be put into the CPU in any order to process, now need to design a solution to the CPU to deal with this batch of tasks, the minimum time required to find the smallest time.
Enter a description:

The input consists of two lines: the
first behavior integer n (1≤n≤50) The
second behavior n integers length[i] (1024≤length[i]≤4194304), which means that each task has a length of length[i]kb, each of which is a multiple of 1024.


Output Description:
Output An integer that represents the minimum amount of time to process

Enter an example:
5
3072 3072 7168 3072 1024

Output Example:
9216
Personal thinking:

1. Select the smallest 2 tasks and 2 cup to start processing these two tasks
1.1. If two are completed at the same time, find the smallest 2 tasks remaining in the task and proceed with the task processing
1.2. Until the remaining tasks are 1 or 2
2.1. If a task is completed, find the smallest 1 tasks remaining and proceed with the task processing

After thinking about it, I started writing code, and the final test result was 30% pass rate.

Also from the correct code for this problem learned, I write the code to improve the space is too large. One is to deal with the choice of ideas, the second is the simplicity of the code, since it is Python, why not play its advantages. correct results (cattle net id:Mr.Mary):

n= Int (raw_input ()) arr=[Int (i) for I and Raw_input (). Strip (). Split ()] H=set (arr) for I in Arr:for J in List (h): H.add (i+j) h=[i for i in H if I>=sum (arr)/2] print min (h) skillfully uses Python's set and list.

First, the input task is processed with set to become a task set with no Duplicates H

Then increase the H inside processing time, for example the topic the example increases to finally, the result of H for

H Set ([3072, 7168, 4096, 15360, 19456, 23552, 5120, 8192, 12288, 16384, 20480, 24576, 1024, 6144, 9216, 13312, 17408, 2150 4, 2048, 11264, 10240, 14336, 18432])

Two cup, the input of the total task time divided by 2 as the benchmark for H filter, and finally remove the smallest value, that is the desired answer.

The key is to consolidate the time of the task, to SUM/2 as the benchmark for time filtering.



2. finally the weekend. Small easy to walk in the streets of the city to find Friends party, suddenly the server sent alarm, small easy need to immediately back to the company to fix the emergency bug. Assuming that the urban area is an infinitely large region, each street assumes the coordinates are (x,y), the small Yi is present in (0,0) the street, the Office on (Gx,gy) street. Small easy around a number of taxis taxi points, small easy to go to the office there are two options, one is to walk to the company, the other is to walk to a taxi point, and then from the location of the taxi to the company. Each move to the adjacent street (horizontal or vertical) will take walktime time, and a taxi will take taxitime time. Small easy need to get to the company as soon as possible, now small Yi want to know how fast he needs to spend time to go to the company.
Enter a description:

The input data includes five elements:

the number of taxi cabs around the first act n (1≤n≤50)

second act the horizontal axis of each taxi cab point Tx[i] ( -10000≤tx[i]≤10000)

third act The ordinate of each taxi cab point Ty[i] ( -10000≤ty[i]≤10000)

Act IV Office coordinates gx,gy ( -10000≤gx,gy≤10000), separated by space

, fifth Act walking Time Walktime (1≤walktime≤1000) and Taxitime (1≤taxitime≤1000), separated by spaces


Output Description:
The output of an integer indicates that the easiest time to get to the office

Enter an example:
2
-2-2
0-2
-4-2
15 3

Output Example:
42
Personal thinking:x or y every change +-1, Walktime and Taxitime are added once
Statistics 0,0 to the taxi point to the company all the time, take the minimum value
How many of these things are there: 16, but in these 16 cases, there are a few of the following computational properties that are the same
My idea is so simple that I want to be complicated. correct answer (cattle net id:panzerfaust):While true:line = Sys.stdin.readline ()
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.