[Puzzle + Summary]20151012 greedy

Source: Internet
Author: User

1. Preface

Noip before the first bullet-the greedy topic from homocysteine. Because I took the night before the exam hand cheap (really a cheap hand) to bzoj on the brush and then happened to that question is today's exam question, the result happened again by the homocysteine notice ... In fact, I had no intention to know. It turned out to be such a strange thing. Greedy what feel good, another problem has been done before, for the concept of "three points" I am still very deep impression.

2, Lawnmower lawn mower

Approximate test instructions: In the 0-1 rectangle of the n*m, from the upper left (0,0), you can only move in two directions at a time--down, left, or right. If the remainder of the current line I is 2 to the right, otherwise to the right. The shortest circuit is used to pass all 1 points.

Summary: Only 60 points, blame I did not see the topic. Because you only need to go through all 1 points, so if the last few lines do not have 1, there is no need to walk to the back of a few lines, this place needs a special sentence.

The puzzle: Greed. First, assuming that each row must have 1, then we first find the leftmost 1 position of each row and the 1 position at the right end. Because the requirements must follow a path similar to the "S" type, for even rows, the transverse distance is a larger value from the current position to the far right of the current row and the next row, and then moves down one grid; odd rows instead, move from the current position to the lower left of the current row and next row, and then down one grid.

3. Price Pricing (Bzoj 4029)

Link:

4. Food takeaway (Bzoj 3874)

Link:

5. Xor XOR Game

Approximate test instructions: give the number of n, each can be selected two number of different or, and assigned to one, can be different or countless times, to find the largest number of N and.

Exercises

We can use this n number to xor each other until each number cannot be reduced (that is, to a minimum) (The solution: greedy thought, first the number of bits of the highest bit of the number of different, and then through the highest bit ratio of the lower vector, the highest number of high-bit to small. ), and then we can use the other number to make the first XOR a maximum value. (It can be found that: 1: In the minimum, the highest bit of the binary number is the first and only one, similar to the linear basis.) (Otherwise, you can use two number XOR to become two smaller values) 2: The maximum value must be the largest value of the entire sequence, you can find that all values to a minimum, if the binary number is the highest bit of the number of the first bit, then the number of binary maximum is greater than I must be 0 in the first bit, That is, all non-0 values are different or can have XOR maxima).
It can be found that the last sequence obtained by using the maximal XOR other minima is a feasible sequence.
Prove that each solution is maximum:
Taking the minimum of I and the first XOR, set to get s, assuming that you can also get a larger value, then it will certainly be another minimum of B in XOR. The binary highest bit of B is j, so the value of s in the J bit must be 0. (otherwise not better) easy to know: The first maximum value in the J bit must be 1. While S-J is 0, it is known that the J-bit of the minimum value of I is 1 (1^1 = 0). It is illegal to find this. (Such a minimum of ^b can be changed to a lesser value than to a minimum). Complexity: O (n^2).

[Puzzle + Summary]20151012 greedy

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.