[Puzzle + Summary]20150920/20150921

Source: Internet
Author: User

1, 20150920

<1> k Short Path

Approximate test instructions: Look for a short path on the map.

Puzzle: dijkstra+a* algorithm, can also use Dijkstra, even have high complexity but still can live DFS mess.

<2> longest common substring

Approximate test instructions: Find the longest common substring of two strings.

Problem: suffix array naked. O (n^2) rules only 30 points.

<3> Gymnasium

Approximate test instructions: Double-weighted segment coverage max problem.

The problem is that there is nothing to do with greed or anything, at least not yet heard to do so. The only one known to be able to AC is the minimum cost maximum flow, and there is a dynamic plan that is not understood. A detailed explanation of the minimum cost maximum flow:

① processing costs: First of all there must be a doubt: there is no cost, only the proceeds. This place is very ingenious, because in the bare minimum cost of the maximum flow we are as far as possible to find the cost of small, here we try to find a large profit, then we can put the proceeds as a negative value for the cost calculation, there is a minimum cost is the maximum benefit;

② composition Ideas: Assuming a total of n days, first of all, we set 1~n a total of n nodes, to connect them from small to big, for each path, the profit is 0, because if from day I to the i+1 day nothing is dry, there is no income, traffic is 2, because there are two venues;

③ Add an enterprise: For an enterprise requires the occupation on the first X days to the Y day, the income is Z. According to the above composition, if you want to introduce the enterprise, you need to occupy a piece of space, which is equivalent to 1 of the flow, the cost is the opposite number of proceeds. The two points connected are point x and Point y+1.

④ Source point: Set node No. 0 and N+1 node, the cost, revenue is also 2, 0;

④ Run maximum flow: Minimum cost maximum flow starting from node No. 0, the answer is minimum cost/maximum benefit.

Very like this way of thinking, although the network flow this piece of complexity is generally relatively high, constant is not small, but for small data, or really did not think of positive solution, with the network flow is also good, the code is relatively not difficult to write.

2, 20150921

<1> Scout

Probably test instructions: there is a map of the 3*n 0-1, asking from the leftmost to the far right, only 0 can go through. When and only if you are currently in the middle row, you can shift the values of the 8 squares around clockwise. The minimum number of transfers to meet the conditions.

dp/: Memory Search.

<2> cipher Strings

Probably test instructions: There is a cipher string and original string, which requires the original string to be restored as an answer. Restore Mode: For each character of the answer, a cipher string is added to the front, but some other characters are mixed.

The puzzle: O (n) simulation.

<3> Frontal Battlefield

Approximate test instructions: Give a 10^9 within the number of N, the need to find some number a in the 10^9, so that the last nine digits of the a*a is N. Both N and a are allowed to have a leading 0.

Summary: I have nothing to say. It's a really stupid push. Alas. I'm so desperate to find the optimization of odd-even relationship from the nature and inference of the total square number, the Mantissa judgment optimization and so on, the optimization to 1.8-3s, can not find out. The result is conceivable to be 0 points. After the exam, I saw that the code of the others was almost collapsed. The same enumeration, I did not think of the bitwise to search? Oh.

The first can be clearly 9 digits, then from the first position from 0 to 9 enumeration, as long as the bit is satisfied, recursion to the next bit. The amount of state is greatly reduced, apparently not so-called O (n^m). Oh.

<4> Save Fish

Approximate test instructions: Give a map, starting from point 1th, each time you can choose a successor node as the next one more starting point. In other words, if you currently select the number 2nd point from Point 1th, you can find the node from point 1th and 2nd respectively next time. Ask the quickest to find all the nodes in a few times.

Summary: The topic itself seems to have a problem with STD, violence 80 points. We have all kinds of greedy way, even the sample can not pass the greedy unexpectedly AC, do not think. I have thought about it, but obviously the mistake can not be wrong again, also added optimization. But the optimization of the process of writing a stupid place, I really have no language, although I am not sure whether this method is completely correct, but 90 points is better than 40 points.

The puzzle: Greed. I can't justify saying which method is right because of the problem of the data. First for a point u if can be selected by point V, then the Father node that is called V is U. My approach is, for any node, first preprocessing the number of nodes that can be selected, and whether he has only one father, whose father's son has the number of such nodes. The node 1th is initially added to the set of operational nodes, and for the nodes currently being processed, preference is given to those nodes that only recognize the current node as the father, where the son node of the son node is the most preferred, until all nodes are in the operational node collection.

[Puzzle + Summary]20150920/20150921

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.