Luogu P2587 Problem Solving Report

P2587 [ZJOI2008] Bubble Hall

Topic description

During the XXXX NOI, in order to strengthen the communication between the players from various provinces, the organizing committee decided to organize an inter-provincial e-sports competition. The representative team of each province is composed of n players. The competition items are online games suitable for all ages. Bubble Hall. Before each game, the coaches of the opposing sides submit a list of contestants to the organizing committee, which determines the order in which the contestants will play. Once determined, they cannot be modified. In the game, the No. 1 player, No. 2 player..., No. n player of the two sides fought against each other, and a total of n games were played. 2 points for each win, 1 point for a draw, and no points for a loss. In the end, the single-game scores of both sides are added to obtain the total score, and the team with the higher total score will advance (the same total score will be decided by lottery).

As the team leader of the Zhejiang team, you have already understood the bubble hall level of all the players in each province in advance, and used a strength value to measure it. In order to simplify the problem, we assume that the players are completely free from any external factors in the game, that is, the stronger player will definitely defeat the weaker player, and the two players with the same strength will definitely draw. With absolutely no idea what strategy the opponent will use to determine the order of appearances, all teams have adopted a strategy of completely randomizing the order of appearances.

Of course you don't want to play the game in such a vague way. You want to know in advance how many points Zhejiang will get in the best and worst case scenarios.

Input and output format

Input format:

The first line of the input file is an integer n, representing the number of people in each team.

The next n lines, each with an integer, describe the strength values ​​of the n Zhejiang team players.

The next n lines, each with an integer, describe the strength of your opponent's n players.

In 20% of the data, 1<=n<=10;

In 40% of the data, 1<=n<=100;

In 60% of the data, 1<=n<=1000;

In 100% of the data, 1<=n<=100000, and the strength value of all players is between 0 and 10000000.

Output format:

The input file contains two integers separated by spaces, which respectively indicate how many points the Zhejiang team can score in the best and worst cases. Do not output extra whitespace characters at the end of the line.


This data, this feeling, is obviously greedy, Tian Ji is racing horses

Um? No, there seems to be a problem with Tian Ji's horse racing.

Konjac's wonderfully greedy thought process begins

  • The first stage: sweep along both sides together

Well, sort this first, let's go out together

Um? If A wins, roar, A, you can’t compare to others, so let’s continue with the next one.

Happy to have two funny examples of fried chicken.

It's better to be equal, sometimes it's better to wait, and sometimes it's better not to hate it.

Whoops, twenty minutes later

    int cnt=1,ans=0,k=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]>b[cnt])
        {
            cnt++;
            ans+=2;
        }
        else if(a[i]==b[cnt]&&a[i+1]!=b[cnt+1])
        {
            ans++;
            cnt++;
            k++;
        }
        else if(k)
        {
            k--;
            ans++;
        }
    }

looks great

Lu Diyue frowned and found that things were not that simple.jpg

  • The second stage of Tian Ji's horse racing
    , come out and solve the problem

study with careful reference(excerpt)After solving the problem

What must be optimal?

When the current minimum value a in A cannot be happy with the minimum value b in B, it will be O if the maximum value of the opposite is spelled out.

But in the case of equal, we have to discuss and think a little bit

When is the equal situation handled?

The lock meter is wrong. The simulation thinks that if there is any surplus between the two chains, it must be a part of each other.

    int ans=0;
    int l1=1,r1=n,l2=1,r2=n;
    while(l1<=r1&&l2<=r2)
    {
        if(a[r1]>b[r2])
        {
            r1--;
            r2--;
            ans+=2;
        }
        else if(a[l1]>b[l2])
        {
            l1++;
            l2++;
            ans+=2;
        }
        else
        {
            ans+=(a[l1]==b[r2]);
            l1++;
            r2--;
        }
    }

2018.4.28

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325383705&siteId=291194637