题解:Codeforces Round 964 (Div. 4) B
B. Card Game
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output
Suneet and Slavic play a card game. The rules of the game are as follows:
- Each card has an integer value between \(1\) and \(10\).
- Each player receives \(2\) cards which are face-down (so a player doesn't know their cards).
- The game is turn-based and consists exactly of two turns. In a round, both players pick a random unflipped card and flip it. The player who flipped a card with a strictly greater number wins the round. In case of equality, no one wins the round.
- A player wins a game if he wins the most number of rounds (i.e. strictly greater than the other player). In case of equality, no one wins the game.
Since Suneet and Slavic aren't best friends, you need to calculate the number of ways the game could happen that Suneet would end up as the winner.
For a better understanding, please check the notes section.
Input
The first line contains an integer \(t\) (\(1 \leq t \leq 10^4\)) — the number of test cases.
The first and only line of each test case contains \(4\) integers \(a_1\), \(a_2\), \(b_1\), \(b_2\) (\(1 \leq a_1, a_2, b_1, b_2 \leq 10\)) where \(a_1\) and \(a_2\) represent the cards Suneet has, and \(b_1\) and \(b_2\) represent the cards Slavic has, respectively.
Output
For each test case, output a single integer — the number of games Suneet would win considering all possible games.
题意
Suneet和Slavic各有两张牌,他们将进行两轮游戏,每轮游戏掀开自己未掀开的牌中的任意一张
- 若我方该轮掀开的牌比对方大,则我方获胜。
- 若我方该轮掀开的牌比对方小,则对方获胜。
- 若牌双方相同,则无人获胜。
求我方获胜次数比对方多的情况
Example
Input
5
3 8 2 6
1 1 1 1
10 10 2 2
1 1 10 10
3 8 7 2
Output
2
0
4
0
2
Note
Consider the first test case when Slavic starts with the cards that have the values \(2\) and \(6\), and Suneet starts with cards that have the values \(3\) and \(8\). The game could happen in \(4\) different ways:
-
Suneet flips \(3\) and Slavic flips \(2\). Suneet wins the first round. Then, Suneet flips \(8\) and Slavic flips \(6\). Suneet wins the second round as well. Since Suneet won \(2\) rounds, he wins the game.
-
Suneet flips \(3\) and Slavic flips \(6\). Slavic wins the first round. Then, Suneet flips \(8\) and Slavic flips \(2\). Suneet wins the second round. Nobody wins since both players won an equal amount of rounds.
-
Suneet flips \(8\) and Slavic flips \(6\). Suneet wins the first round. Then, Suneet flips \(3\) and Slavic flips \(2\). Suneet wins the second round as well. Since Suneet won \(2\) rounds, he wins the game.
-
Suneet flips \(8\) and Slavic flips \(2\). Suneet wins the first round. Then, Suneet flips \(3\) and Slavic flips \(6\). Slavic wins the round. Nobody wins since both players won an equal amount of rounds.
注
考虑第一个测试案例,当斯拉夫克开始时有牌值为 \(2\) 和 \(6\) 的牌,而苏尼特开始时有牌值为 \(3\) 和 \(8\) 的牌。游戏可能以 \(4\) 种不同的方式进行:
-
Suneet 翻 \(3\) ,Slavic 翻 \(2\) 。Suneet 赢了第一轮。然后,Suneet 翻 \(8\) ,Slavic 翻 \(6\) 。Suneet 同样赢得第二轮。由于 Suneet 赢了 \(2\) 个回合,所以他赢了这局棋。
-
Suneet 翻 \(3\) ,Slavic 翻 \(6\) 。斯拉夫赢得第一轮。然后,Suneet 翻 \(8\) ,Slavic 翻 \(2\) 。Suneet 赢第二轮。由于双方赢得的回合数相同,因此没有人获胜。
-
Suneet 翻转 \(8\) ,Slavic 翻转 \(6\) 。Suneet 赢了第一轮。然后,Suneet 翻出 \(3\) ,Slavic 翻出 \(2\) 。Suneet 同样赢得第二轮。由于 Suneet 赢了 \(2\) 个回合,他赢得了游戏。
-
Suneet 翻 \(8\) ,Slavic 翻 \(2\) 。Suneet 赢了第一轮。然后,Suneet 翻出 \(3\) ,Slavic 翻出 \(6\) 。斯拉夫赢得这一轮。由于双方赢得的回合数相同,因此没有人获胜。
题解
只要选定了我方一张牌和对方一张牌,另外两张牌也已经锁定了
因此:假设我有牌 \(a\) 、\(b\) ,对方有牌 \(c\) 、\(d\)
只要计算
- \(a\) 对 \(c\) 与 \(b\) 对 \(d\)
- \(a\) 对 \(d\) 与 \(b\) 对 \(c\)
两种的胜负情况
再乘 \(2\)(因为可以调换顺序)
然后输出就可以了
代码
#include <bits/stdc++.h>
#define int unsigned long long
#define INF 0x3f3f3f3f
#define all(x) x.begin(),x.end()
int t = 1;
void solve() {
int a,b,c,d;
std::cin >>a >> b >> c >> d;
int ans = 0;
int ans1 = 0,ans2 = 0;
if((a > c && b >= d) || (a >= c && b > d)) ans += 2;
if((a > d && b >= c) || (a >= d && b > c)) ans += 2;
std::cout << ans << "\n";
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
std::cin >> t;
while(t--) solve();
return 0;
}
posted on 2024-08-07 16:01 Jiejiejiang 阅读(79) 评论(0) 编辑 收藏 举报