Simulate test1 day1

Source: Internet
Author: User

Linhu giant

Sort

Find the number of intervals in which the letters A, B, and C appear in the same number of times in the string.

The initial solution is prefix and, with a (I), B (I), C (I) representation before position I (including I) number of letters A, B, and C, and the left and right endpoints L and R of the enumerated range. If a (R)-A (L-1) = B (R)-B (L-1) = C (R)-L-1) is a group of solutions. The complexity of O (n2) can exceed 70%.

Positive Solution: Get the above deformation,

A (R)-B (R) = L-1)-L-1)

B (R)-C (R) = L-1)-C (L-1)

Therefore, we can save a (I)-B (I) and B (I)-C (I) and sort them by double keywords. If a (I)-B (I) = a (j)-B (J), B (I)-C (I) = B (j) -C (j): In the final ordered sequence, the nodes corresponding to I and j must be in the same region, each node in the region has the same A-B and B-C. Therefore, as long as the size of the continuous region is calculated using linear time, the final result is sum {n * (n-1)/2, and N is the length of each region }.

Note that a (I)-A (j) indicates a range (I, j] or [I + 1, J], then a (I) -A (1) indicates (1, I] ([2, I]), and cannot represent [1, I]. When a (I) = B (I) = C (I), it is possible that the [1, I] must be a solution. So add (0, 0) to the sequence to be sorted (in fact (0, 0) is a (0)-B (0), B (0) -C (0), A (I)-A (0) can represent the range [1, I]).

?

Frog God

Status compression motion Gauge

Find the number of path entries whose path product is the total number of workers on the Dag.

The initial solution is brute-force search, which can only exceed 30%.

Positive Solution: based on the nature of the complete number of dimensions, it can be concluded that the number of times of each prime factor of the full number must be an even number, and the maximum number of N is 90, therefore, the prime factor of the complete number of percentages obtained after a path cannot contain a prime number of 47 or more (if 47 is included, there must be at least two, only one 47 of the numbers with 47 as the factor is smaller than 90, so it is impossible to see 47 twice ). In 1 ~ In 45, there are a total of 14 prime numbers. Therefore, a binary bit can be used to indicate whether a prime factor has an odd or even number of times. All binary digits are in the same status, the default state of each node is preprocessed. It is recorded as ST (I) and F (I, j) is used) indicates the number of paths that end with I when I node is in status J (here, status J is the sum of the statuses from a node to end with I node, can be obtained by an exception or operation), then

F (I, j) = sum {f (K, J ^ st (I), <K, I> ε e}

Initial Condition: f (I, ST (I) = 1

F (I, ST (I) = 1 here does not mean that from I to I is a solution, but f (I, ST (I )) is a possible state, because in all f (I, j), many States cannot be reached.

The final result is ans = sum {f (I, 0), I, V}

(When the status of a node is 0, it indicates that the number of all quality factors is an even number, which is a full number of cores)

?

Defeat the demon

Binary answer + query set

Question: to give a graph and several points, delete the edge with the weight less than or equal to d so that the given points are not connected, and find the minimum value of D.

Solution: Obviously D is the largest edge weight in the final result, and the question requires the minimum value of the maximum value. Generally, this type of question can be considered using a binary answer method. Divide the value of D in the enumeration, delete the edge less than or equal to d in the graph, query the set and connected points, and then use the query set to determine whether the two points are connected. However, at first I used DFS traversal for merging, so the subsequent vertices have timed out. In fact, we can merge every edge in the number group of enumeration edge sets.

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.