P1199 Three Kingdoms games and p1199 Three Kingdoms games

Source: Internet
Author: User

P1199 Three Kingdoms games and p1199 Three Kingdoms games
Description

Xiao Han enjoys computer games. He is playing a game called "Three Kingdoms" these days.

In the game, Xiao Han and the computer held each other and formed their respective troops to fight. There are a total of N military commanders (N is an even number and not less than 4) in the game. There is a "tacit understanding" between any two military commanders, indicating that if the two military commanders are combined as a match, the power of the combination. Before the game starts, all martial arts will be free (called the free martial arts force, once a free martial arts is selected as a member of a certain army, then it will no longer be a free martial arts force). In other words, the so-called liberal arts will not belong to any party.

At the beginning of the game, Xiaohan and computers should select their own troops from the free military commanders. The rule is as follows: Xiaohan selects one from the free military commanders to join his army, then the computer also selects an army from the Free Army. Next, follow "Xiao Han → computer → Xiao Han → ......" Select the generals until all the generals are evenly allocated. Then, the program automatically picks out a pair of tacit values from the army of both parties

The generals of the generals represent their own troops in the second-to-second competition. A pair of generals with a higher tacit understanding won the battle, indicating that the two armies fought and the one with the winning generals won the victory.

It is known that the principle of selecting a military force on the computer side is to destroy the strongest combination that the opponent will form in the next step. The specific strategy adopted by the computer is as follows, it will try to pair each of its opponent's military commanders with each of the current free military commanders one by one to find the most tacit pair of military commanders in all pairs, and select the free military commanders in the group into their own army. The following is an example of a computer's selection strategy. For example, there are a total of six military commanders in the game. Their tacit understanding values are shown in the following table:

The selection process is as follows:

Xiao Han wants to know if the computer always sticks to the above strategy in a game, is it possible that he must

Win? If so, in all possible victory endings, the maximum tacit understanding of the generals used for the competition is

Less? We assume that during the entire game process, both sides can see the generals in the free military force and the generals of the other army at any time. To simplify the problem and ensure that the tacit understanding values of different generals are different.

Input/Output Format

Input Format:

 

The input file name is sanguo. in, N rows in total.

The first act is an even number of N, indicating the number of military commanders.

From row 2nd to row N, row (I + 1) has (Ni) non-negative integers separated by a space

Opening, indicating that the I military commanders and I + 1, I + 2 ,......, Tacit understanding value between the N military commanders (0 ≤ tacit understanding value ≤ 1,000,000,000 ).

 

Output Format:

 

The output file sanguo. out contains 1 or 2 rows.

If a given game input has a sequence that allows Xiao Han to win, output 1 and output another line.

The maximum tacit understanding of the generals finally selected by Xiao Han in all the winning cases.

If there is no selection order that can make Xiao Han win, 0 is output.

 

Input and Output sample input sample #1:
6 5 28 16 29 27 23 3 20 1 8 32 26 33 11 12 
Output sample #1:
132
Input example #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 sample #2:
177
Description

[Data Scope]

For 40% of data, N ≤ 10.

For 70% of data, N ≤ 18.

For 100% of data, N ≤ 500.

 

Based on the question, we can exit two conclusions:

1. Because computers break up the optimal solution every time, computers cannot win.

2. Since the optimal solution has been removed, players only need to find a small one each time.

Because every computer is not the optimal solution

Each time a player is the current optimal solution,

So in the end, players must win.

 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 #define lli long long int  7 using namespace std; 8 const int MAXN=1001; 9 void read(int &n)10 {11     char c='+';int x=0;bool flag=0;12     while(c<'0'||c>'9')13     {c=getchar();if(c=='-')flag=1;}14     while(c>='0'&&c<='9')15     {x=x*10+(c-48);c=getchar();}16     flag==1?n=-x:n=x;17 }18 int n;19 int a[MAXN][MAXN];20 int num=0;21 int comp(int a,int b)22 {23     return a>b;24 }25 int main()26 {27 //    freopen("sanguo.in","r",stdin);28 //    freopen("sanguo.out","w",stdout);29     read(n);30     for(int i=1;i<=n;i++)31         for(int j=i+1;j<=n;j++)32         {33             int p;34             read(p);35             a[i][j]=p;36             a[j][i]=p;37         }38     int ans=-1;39     for(int i=1;i<=n;i++)40     {41         int fi=0,se=-1;42         for(int j=1;j<=n;j++)43         {44             if(a[i][j]>fi)45             {46                 se=fi;47                 fi=a[i][j];48             }49             else if(a[i][j]>se)50                 se=a[i][j];51         }52         ans=max(ans,se);53     }    54     printf("1\n%d",ans);55     return 0;56 }

 

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.