I guessed a conclusion that the merger would be a merger and that a hostile deal would have to be made when a hostile transaction was required.
Then the merger would have to take the biggest two to merge.
As for hostile trading, it is important to kill each other's biggest company.
So various categories discussed ... Look at the code well ...
#include <cmath>#include<queue>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespaceStd;typedefLong LongLL;#defineN 100000 + 5int_, N, M;priority_queue<LL> q[2];inline LL getint () {CharCH ='\ n'; for(; CH >'9'|| Ch <'0'; CH =GetChar ()); LL Res= CH-'0'; for(ch = getchar (); Ch >='0'&& CH <='9'; CH =GetChar ()) Res= (Res <<3) + (res <<1) + CH-'0'; returnRes;} InlineBOOLSolve ()//returns the winner's number (0 or 1){ for(intOP =0; ; Op ^=1) { if(Q[op].empty ())returnOp ^1;//Section 1: If the current company does not have a branch, the natural winner is the other side. if(q[op].size () = =1)//Section 2: If there is only one branch left in the current company { if(Q[op].top () < Q[op ^1].top ())//Case 1: If the other person's most valuable company is worth more than the company, the natural winner is the other. returnOp ^1; Else if(Q[op].top () = = Q[op ^1].top () && q[op ^1].size () = =1)//Case 2: There's only one branch left on either side, and the value is the same, so the draw, the winner, is the man. return 1; Else if(Q[op].top () > Q[op ^1].top ()) Q[op ^1].pop ();//Case 3: Only hostile transactions are allowed here. } Else //Section 3: If the current company has many branches{LL max_1=Q[op].top (); Q[op].pop (); LL max_2=Q[op].top (); Q[op].push (max_1); if(q[op ^1].size () = =1)//Case 1: If the other party has only one branch, then the current company can only merge. {Q[op].pop (), Q[op].pop (); Q[op].push (Max_1+max_2); } Else{LL _max_1= Q[op ^1].top (); if(_max_1 >= max_1)//Case 2: If the largest branch of the current company is not the largest branch, then it can only be merged. {Q[op].pop (), Q[op].pop (); Q[op].push (Max_1+max_2); } Else{Q[op^1].pop (); LL _max_2= Q[op ^1].top (); Q[op^1].push (_max_1); if(_max_1 + _max_2 >= max_1 +max_2) { //Case 3: If the current company's first two branches value and less than equals the other two major branch value and, that must be hostile trading, otherwise the initiative is not on their side. Q[op ^1].pop (); } Else //Case 4: If the current company's top two branches value and greater than the other two major branch value and, then even if the merger of the initiative is on its own side, then the merger chant. {Q[op].pop (), Q[op].pop (); Q[op].push (Max_1+max_2); } } } } }}intMain () {#ifndef Online_judge freopen ("3983.in","R", stdin); Freopen ("3983.out","W", stdout); #endif while(SCANF ("%d%d", &n, &m) = =2) { while(! q[0].empty ()) q[0].pop (); while(! q[1].empty ()) q[1].pop (); for(inti =1; I <= N; i + +) q[0].push (Getint ()); for(inti =1; I <= m; i + +) q[1].push (Getint ()); BOOLWinner =Solve (); printf ("Case %d:", ++ _); Puts (winner==0?"Takeover Incorporated":"buyout Limited"); } #ifndef Online_judge fclose (stdin); Fclose (stdout); #endif return 0;}
Bzoj 3983 takeover Wars Problem solving report