1034: [ZJOI2008] Bubble Hall BNB
Description
During the Noi period, in order to strengthen the exchanges between the provinces, the organizing committee decided to organize an inter-provincial e-sports competition, the representative of each province
The team is made up of N players and the event is an online game bubble Hall for all ages. Before each match, the coaches of the two sides submitted a copy to the organizing committee
The list of contestants determines the order in which the contestants will play and shall not be modified once determined. In the race, a contestant of both sides, contestant No. second ..., n
Players to catch the fight, a total of n games. Each win a match 2 points, the level of 1 points, lose a score. end up adding a single field score to both sides
Get the total score, the high score of the team to advance (the total score of the same decision). As the leader of Zhejiang team, you have already put all the players in the province in advance to the bubble Hall water
Know the plain and measure it with a strength value. To simplify the problem, we assume that the player is completely unaffected by any external factors in the game.
, that the strength of the players must be able to overcome the weak players, and two players of the same strength must fight flat. Because I have no idea what the opponent will use
Strategies to determine the order of appearances, so all teams have adopted a strategy of completely randomly determining the order of appearances. Of course you don't want to do that.
The game is not white. You want to know in advance how many points the Zhejiang team will get in the best and worst case scenario.
Input
The first behavior of the input is an integer n, representing the number of each team. The next n rows, an integer per line, describe the N-position of the players in the Zhejiang team
Strength value. The next n lines, an integer per line, describe the strength of your opponent's N-players. The number of,1<=n<=10; 40% in 20% of the data
According to the data in,1<=n<=100; 60%,1<=n<=1000; 100% of the data, 1<=n<=100000, and the strength of all players in 0 to 100
Between 00000.
Output
including two spaces separated by a number of integers, respectively, the Zhejiang team in the best and worst case, respectively, how many points can be. Do not output excess at the end of the line
White space characters.
Sample Input2
1
3
2
4Sample Output2 0
Sample DescriptionWe say 4 players are a,b,c,d respectively. The following 4 types of PvP may be present, preferably 2 points, and a worst case score of 0.
1234
Zhejiang??? Results Zhejiang??? Results Zhejiang??? Results Zhejiang??? Results
Player A C negative a D negative B C wins b d negative
Contestant number second B d negative B C wins a D negative a C negative
Total score 0 2 2 0This problem, a look there is a very strong field bogey horse racing is the sense of sight (actually AH Hello!) )。 so naturally think of using greed to solve the problem. As for me this is not an algorithm I am not very clear, but I will be a step-by-step to clarify my code, I want to let everyone can understand!
1InlineLong LongGetans (Long Long*a,Long Long*b)2 {3 Long Longans=0;4 intH=1, t=N;5 inth1=1, t1=N;6 while(h<=t)7 {8 if(A[h]>b[h1]) ans+=2, h++,h1++;9 Else if(A[t]>b[t1]) ans+=2, T--, t1--;Ten Else One { A if(A[h]==b[t1]) ans+=1; -h++,t1--; - } the } - returnans; - } -
This is the core part of the problem, of course, the data has been sorted beforehand.
The whole process is to find the weakest players and B-side of the weakest players to play, if you play, hit, but to consume the opposite of the strongest person, win on the + 2 draw on the + 1 points, and then record the current AB team weakest strongest person, the final output answer on the line.
In addition this problem is also worth noting is that our most advantageous bureau is the other side of the most inferior bureau, that is, the second is to take the other side when we, let each other play an advantage, the final output of the answer when the 2*n-ans on the line.
The last reminder: Do not open long long see ancestors, ten years Oi an empty!
"BZOJ1034" provincial team player whipped Bubble Hall (I do not know what algorithm)