Hdu1052 (Tian Ji's horse racing greedy)

Source: Internet
Author: User

A good question, but it is indeed a greedy good question. After thinking for a long time, it has been unable to solve the draw situation. I finally came up with my own ideas based on others' ideas.

Some steps are required. There are four steps.

1. the slowest horse in the current State is faster than the slowest horse in the opponent. This is because the slowest horse in the opponent is slower than that in the field, tian Ji Won this winning game at the lowest price for the sake of the following conditions. 2. At present, Tian Ji's slowest horse is slower than his opponent's slowest horse, indicating that Tian Ji's slowest horse is slower than all his opponent's horse, tian Ji will naturally use this horse to consume the fastest horse of his opponent in this case, so he will use the slowest horse to compare with the fastest horse of his opponent in this case.

3. Similarly, Tian Ji's fastest horse is faster than his opponent's horse.

4. Similarly, Tian Ji's fastest horse is slower than his opponent's fastest horse, and Tian Ji's slowest horse consumes the fastest horse from his teammates. Because the opponent's fastest horse will win, it is necessary to minimize losses.

That is, if either of the four situations occurs, the preceding steps must be followed. However, there is another situation, that is, the above four situations suddenly show two. So which one is to be executed first? If you think about it, you can find that the final result is the same when you first execute the statement.

In the end, there may also be a dead scene, that is, when both ends are equal. At this time, you can assume that you use the shortest horse of Tian Ji to match the fastest horse of your opponent, there will be two situations: one is that the fastest horse of the opponent is faster than the slowest horse of Tian Ji, but the fastest horse of Tian Ji is faster than the slowest horse of the opponent, therefore, in the worst case, Tian Ji can make a comparison between the fastest and slowest horse and the fastest and slowest horse, this is the same as the draw on both sides or the draw on one side. Second, the speed of all horses in the current state is the same, so that the results of any policy are the same.

According to this idea, this question can be solved.

Hdu1052

 

 

# Include <iostream> # include <stdio. h> # include <string. h> # include <math. h> # include <algorithm> # include <string> # include <queue> # include <stdlib. h> using namespace STD; # define n 1100int Ga [N], GT [N]; int main () {int N; while (scanf ("% d", & N) & N) {for (INT I = 0; I <n; I ++) scanf ("% d", GT + I); For (INT I = 0; I <n; I ++) scanf ("% d", GA + I); sort (GA, GA + n); sort (GT, GT + n ); int ans = 0; int AB, AD, TB, TD; AB = 0, AD = n-1; TB = 0, TD = n-1; int Sign = 0; while (1) {If (Sign = 0) {If (GT [TB]> Ga [AB]) {ans ++; TB ++; AB ++; If (Tb> TD) break;} else if (GT [TB] <Ga [AB]) {If (Ga [ad]> GT [TB]) ans --; TB ++; Ad --; if (Tb> TD) break;} else {If (Ga [ad] = gt [td]) {If (Ga [ad]> GT [TB]) ans --; TB ++; Ad --; If (Tb> TD) break;} else {Sign = 1; // No-party switching mode }}else {If (GT [td]> Ga [ad]) {ans ++; TD --; Ad --; If (Tb> TD) break;} else if (GT [td] <Ga [ad]) {ans --; TB ++; Ad --; If (Tb> TD) break ;} else {If (Ga [AB] = gt [TB]) {If (Ga [ad]> GT [TB]) ans --; TB ++; Ad --; if (Tb> TD) break;} else {Sign = 0 ;}}} printf ("% d \ n", ANS * 200);} return 0 ;}

 

Hdu1052 (Tian Ji's horse racing greedy)

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.