Ping-pong
作者:互联网
Ping-pong Codeforces-1455C
2021.05.01 训练题H
题目大意: 两个角色 Alice 和 Bob 打球,第一次 Alice先发球,之后胜方发球,每个人都有自己的体力值,发球消耗1体力,回球消耗1体力(也可不接),每个人都想让自己胜场最大,问游戏结束后最后的胜场分别为多少
思路: 理解误区:1.保证自己胜场最多并不意味着对方败场最多,也不意味着对方胜场最少 2.当一方体力为0后,比赛将结束,而不是另一方发球
做题方法:若想让自己胜场最多,就无需关心对方是否胜利,也无需关心自己是否输了几次,那么Bob是接球方,他只需要让Alice一直发球,自己不接,等到Alice只剩1体力后,Alice发球后剩下0体力,此时Bob开始回击,每次回击都是胜场,这样他的体力数就是发球数,也是胜场数,这样就充分最大限度的使用了自己的体力换来了最大的胜场数
题目:
Alice and Bob play ping-pong with simplified rules.
During the game, the player serving the ball commences a play. The server strikes the ball then the receiver makes a return by hitting the ball back. Thereafter, the server and receiver must alternately make a return until one of them doesn't make a return.
The one who doesn't make a return loses this play. The winner of the play commences the next play. Alice starts the first play.
Alice has x stamina and Bob has y. To hit the ball (while serving or returning) each player spends 1 stamina, so if they don't have any stamina, they can't return the ball (and lose the play) or can't serve the ball (in this case, the other player serves the ball instead). If both players run out of stamina, the game is over.
Sometimes, it's strategically optimal not to return the ball, lose the current play, but save the stamina. On the contrary, when the server commences a play, they have to hit the ball, if they have some stamina left.
Both Alice and Bob play optimally and want to, firstly, maximize their number of wins and, secondly, minimize the number of wins of their opponent.
Calculate the resulting number of Alice's and Bob's wins.
Input
The first line contains a single integer t (1≤t≤104) — the number of test cases.
The first and only line of each test case contains two integers x and y (1≤x,y≤106) — Alice's and Bob's initial stamina.
Output
For each test case, print two integers — the resulting number of Alice's and Bob's wins, if both of them play optimally.
Example
Input
3
1 1
2 1
1 7
Output
0 1
1 1
0 7
Note
In the first test case, Alice serves the ball and spends 1 stamina. Then Bob returns the ball and also spends 1 stamina. Alice can't return the ball since she has no stamina left and loses the play. Both of them ran out of stamina, so the game is over with 0 Alice's wins and 1 Bob's wins.
In the second test case, Alice serves the ball and spends 1 stamina. Bob decides not to return the ball — he loses the play but saves stamina. Alice, as the winner of the last play, serves the ball in the next play and spends 1 more stamina. This time, Bob returns the ball and spends 1 stamina. Alice doesn't have any stamina left, so she can't return the ball and loses the play. Both of them ran out of stamina, so the game is over with 1 Alice's and 1 Bob's win.
In the third test case, Alice serves the ball and spends 1 stamina. Bob returns the ball and spends 1 stamina. Alice ran out of stamina, so she can't return the ball and loses the play. Bob, as a winner, serves the ball in the next 6 plays. Each time Alice can't return the ball and loses each play. The game is over with 0 Alice's and 7 Bob's wins.
代码详情:
import java.util.Scanner;
public class Ping_Pong {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- != 0) {
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println(a-1+" "+b);
}
}
}
标签:play,ball,return,Ping,Alice,stamina,pong,Bob 来源: https://blog.csdn.net/weixin_45817187/article/details/116357380