[codeforces 1313B] Different Rules (derivation of logical thinking)

It was not written during the game, and there was no idea. . . . TqT

After the competition, I watched other people’s problem solving sessions (my math rookie) https://www.bilibili.com/video/av91242850?p=2

Title link: https://codeforces.ml/contest/1313/problem/B

The meaning of the question: a game is divided into two rounds, each round you have a ranking (everyone's ranking is different in each round). The final ranking is the number one ranked after the two rounds of rankings are added together. What are your possible highest and lowest positions?

answer:

Lowest ranking: Construct other people's scores as much as you can.

1 x + y-1
2 x + y-2
... ...
x + y-1 1

 

A total of x+y-1 can be constructed (including the combination of x and y), then your lowest ranking is min(x+y-1,n)

Highest position:

When x+y<=n , make others' scores greater than n

1 n
2 n-1
3 n-2
.... ....
n 1

Then it can be seen that we can construct a plan where everyone else is greater than n, then the ranking at this time is 1.

When x+y>n , we know that people ranked 1~(x+yn) in a certain round, we cannot construct a plan to make them greater than x+y. So we should lower our ranking in order to improve our ranking. The people whose ranking is 1~(x+yn) in one round, we let them rank the same in another round. Every time a person with 1~(x+yn) is removed, the rank of x and y in the remaining people will be increased by one until X+Y=N, at which time it will be converted to the situation of x+y<=n. Suppose to remove t individuals, x-t+yt=nt; t=x+yn;

Then your highest ranking is min(x+y-n+1, ​​n)

1 1
2 2
3 3
4 4
... ...
x Y
#include <bits/stdc++.h>
using namespace std;

int main(){
    int t,n,x,y;
    cin>>t;
    while(t--){
        cin>>n>>x>>y;
        int minn,maxnn;
        if(x+y<=n) minn=1;
        else minn=min(x+y-n+1,n);
        maxnn=min(n,x+y-1);
        cout<<minn<<' '<<maxnn<<endl;
    }

    return 0;
}

 

Guess you like

Origin blog.csdn.net/qq_44132777/article/details/104698676