1 model (3) day2

Source: Internet
Author: User

Question 1:

Like day1, give m numbers less than N and find the number of occurrences greater than M Div 2. The data range is increased. 1 <= n <= 2 ^ 31 1 <= m <= 3000000

 

Problem solving process:

1. at first, I wrote an array to simulate the hash of the linked list. I used an array to record the number of each category by MoD index P. If all the numbers of each category are less than or equal to half, there is no solution, if there is more than half of the elements, traverse all the elements of the class on one side and save them as a table to see how many times each number appears. Time-out period.

2. After the input is optimized using getchar, the maximum data size is 0.4s.

3. There is also an algorithm. You only need to find a small number in m/2 to see if it is the same as the smallest number. If so, output the answer. Otherwise, there is no solution. Find the k-th largest, fast or tree array or line segment tree.

 

Question 2:

Calculate the maximum continuous string for a ring. Number of elements n <= 1000000

 

Problem solving process:

1. The O (n) algorithm is used to find the maximum continuous string of a linear table. It seems that this question is a transformation of the original algorithm .. Consider the special place of the linear comparison table, that is, you can take the first segment and the last segment. First, directly apply the linear table algorithm, and then take a segment from the special processing header and a segment from the end .. Then, F [I] indicates the maximum prefix and number of the first I, and g [I] indicates the maximum suffix and number of the last I. Then enumerate I and find Max (F [I] + G [I + 1. In the beginning, because the values of F [0] and G [n + 1] are not copied as negative infinity, all the negative data will be lost.

2. There is also an algorithm that is more clever: for the first segment and the last segment, you only need to find the minimum continuous string and then subtract it with the sum of all numbers ..

 

Question 3:

The coordinates of an online station are given. The fare is determined by the distance between the two stations, and the minimum cost for arriving at the station t from station S is obtained.

 

Problem solving process:

1. Write a Floyd for the naked graph topic.

1 model (3) day2

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.