Three Kingdoms Games

Source: Internet
Author: User

Question Description

Xiao Han is fond of computer games, these days he is playing a game called "Three Kingdoms". In the game, the small culvert and the computer each party, the formation of their respective armies to battle. There is a total of N-Generals in the game (n is even and not less than 4), and any two generals have a "tacit value", indicating how powerful the combination would be if the two generals fought as a pair. Before the game began, all the generals were free (called the Free Generals, once a free warlord was chosen as a member of a certain army, then he was no longer a free warlord), in other words, the so-called free generals do not belong to either party. The game begins, the small culvert and the computer to choose from a free warlord to form their own army, the rules are as follows: Xiao Han first elected a free military commander to join his own army, and then the computer from the free generals elected a computer to join the army. Followed by the "small culvert → computer → small Culvert → ..." in the order of the selection of the generals, until all the generals were evenly divided between the two sides. Then, the program automatically from both sides of the army to pick out a pair of the highest tacit value of the generals on behalf of their own army to carry out two to two competitions, with a higher tacit value of the combination of a pair of generals win, said the two armies, with the victory of the winning military combination of the party won. It is known that the principle of choosing a warlord is to try to undermine the strongest combination that the opponent will form next, and it takes the following specific strategies: any time, when it is time to pick up the computer, it will attempt to match each of the generals in the opponent's army with one by one of each of the current free generals, to find out the combination of the strongest pairs And elect the free generals in the group into their own armies. The following is an example of a computer's selection strategy, for example, a total of 6 generals in the game, their tacit understanding of each other as shown in the following table is the number of the warlord:



The two sides select the process as follows:
Optional free-Commander computer when small culvert turns to computer
First Round 5 1 2 3 4 6 4
Second Round 5 3 1 2 6 4 1
Third Round 5 3 6 2 4 1 2
Xiao Han want to know, if the computer in a game always adhere to the above strategy, then it is possible to win? If so, in all possible victories, what is the maximum amount of tacit understanding of the combination of the generals used in the tournament? Assume that during the entire game, both sides can see the generals of the free generals and the generals of the opposing armies at any time. In order to simplify the problem, it is ensured that the tacit value of the different generals ' combinations is not the same.

Input
The 1th act is an even n, representing the number of generals. Line 2nd to Nth Line, i+1 (n-i) a non-negative integer, each two numbers separated by a space, indicating the tacit value between the commander I and the I+1,i+2,......,n (0≤ tacit value ≤1,000,000,000).
Output
If for a given game input, there can be a small culvert to win the election sequence, then output 1, and another line output all the winning case, the small culvert the ultimate selection of the maximum tacit value of the combination of generals. If there is no choice to let the small culvert win the order, then output 0.
Input example
"Input Sample 1"
6
5 28 16) 29 27
23 3 20 1
8 32 26
33 11
12

"Input Sample 2"
8
42 24 10 29 27 12 58
31 8 16 26 80 6
25 3 36) 11 5
33 20 17 13
15 77 9
4 50
19
Output example
"Output Example 1"
1
32
"Output Example 2"
1
77
Other Notes
Data range: n≤500.

From the thought realization, it is a problem of enumerating and greedy. Because, "people" in the process of struggle with the computer, both sides can not achieve the greatest tacit coordination value. Therefore, the "person" can only consider the sub-optimal value, but, in order to be able to cheat the computer, we choose, can only be with our choice of the first military commander with the value of the second-largest military commander (if not a word will be destroyed by the computer). So, it is required that we have to find the value that is the largest value in each row (quite disturbing). Of course, this formulation is based on the matrix that we have shown in the topic. You have to notice that the title gives you the value of the right half of the matrix, you need to put the left half of the value yourself, to be able to follow the line to enumerate (of course, if you want to follow the column, it does not matter, because it is all symmetrical, right).

of course, some students might have thought about it. 0 difficult problem. Unfortunately, this problem will not appear 0. Because, the computer can only destroy "person", moreover, I also thought the method which deceives him, the computer must lose undoubtedly.

Let's take a look at the core part of the program:

Input section:

 for 1 ; I < n; i++)      for1 ; J <= N; J + + )        >> s[i][j];

Symmetric copy section:

 for 2 ; I <= N; i++)      for1 ; J < I; J + +)        = S[j][i];

Find the maximum part of a large value per row:

   for 1 ; I <= N; i++)    {      0;        for 1 ; J <= N; J + +)      {        if (S[i][j] > T1) t1 = s[i][j        ]; if (T1 > t2) swap (t1, T2);      }       if (T < t1) T = t1;    }

It is clear that T for each row of the second large value ( T1 ) is the maximum value. That's what we're asking for.

Complete C + + program:

#include <iostream>#include<cstring>#include<algorithm>using namespacestd;inta[505][505];intMain () {intN; CIN>>N;  for(inti =1; I < n; ++i) {       for(intj = i +1; J <= N; ++j) {cin>>A[i][j]; }   }    for(inti =2; I <= N; ++i) {       for(intj =1; J < I; ++j) {A[i][j]=A[j][i]; }   }   intJSJ =0;  for(inti =1; I <= N; ++i) {      intJS1 =0; intJS2 =0;  for(intj =1; J <= N; ++j) {        if(A[i][j] > js1) js1 =A[i][j]; if(Js1 >js2) {              intJS =js1; JS1=js2; Js2=JS; }      }      if(JSJ < js1) JSJ =js1; }    if(JSJ = =0) {cout<< JSJ <<Endl; }Else{cout<<'1'<<Endl; cout<< JSJ <<Endl; }}

Three Kingdoms Games

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.