#P15593. [ICPC 2020 Jakarta R] Forbidden Card
[ICPC 2020 Jakarta R] Forbidden Card
题目描述
The forbidden card game is played by players numbered from to and a set of cards. Each card has a number written on it between and , inclusive, and there might be more than one card with the same number written on it.
Initially, each player draws two cards one by one. The numbers written on the first card and the second card drawn by the player are and , respectively. It is guaranteed that . After all the players have drawn their cards, the game master (who is not among the players) will decide and designate a number between and , inclusive, to be a forbidden number.
In one turn, a player should play and discard one card from their hand. The card being played should have a number that has not been played before and this number should not be the same as . If a player cannot discard any card on their move, i.e. when they have no card in hand or all the numbers on their cards have already been played or equal to , then they lose the game.
The game is played alternately in a circular manner from player until a player loses the game.
There is a naive deterministic strategy to play this game called first card first where each player prioritizes to play the first card they have (i.e. card numbered ) and play the second card (numbered ) only when they cannot play their first card.
Your task in this problem is to determine for each player the number of different possible forbidden numbers that will cause the player to lose the game assuming all players adopt the first card first strategy.
For example, let there be players and the cards are numbered between and , inclusive. Let represents the number written on the cards drawn by the player. Player 1 has , player 2 has , and player 3 has .
All possible plays are as follows.
- player 3 loses; player 1 plays 2, player 2 plays 4, and finally, player 3 cannot make any move.
- player 3 loses; player 1 plays 1, player 2 plays 4, and finally, player 3 cannot make any move.
- player 1 loses; player 1 plays 1, player 2 plays 2, player 3 plays 4, and finally, player 1 cannot make any move.
- player 3 loses; player 1 plays 1, player 2 plays 2, and finally, player 3 cannot make any move.
- player 1 loses; player 1 plays 1, player 2 plays 2, player 3 plays 4, and finally, player 1 cannot make any move.
- player 1 loses; player 1 plays 1, player 2 plays 2, player 3 plays 4, and finally, player 1 cannot make any move.
In summary, will cause player 1 to lose the game, and will cause player 3 to lose the game. On the other hand, there is no forbidden number that will cause player 2 to lose the game in this example.
输入格式
Input begins with a line containing two integers: (; ) representing the number of players and the maximum possible numbers on the cards, respectively. The next lines each contains two integers: (; ) representing the number on the first and second cards of the player, respectively.
输出格式
Output contains lines. The line contains an integer representing the number of different possible forbidden numbers that will cause the player to lose the game.
3 6
1 2
2 4
4 2
3
0
3
4 10
1 5
2 6
3 7
4 8
4
2
2
2
提示
Explanation for the sample input/output #1
This is the example from the problem description.