B. Card Game

time limit per test

2 seconds

memory limit per test

256 megabytes

Suneet and Slavic play a card game. The rules of the game are as follows:

  • Each card has an integer value between 11 and 1010.
  • Each player receives 22 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 tt (1≤t≤1041≤t≤104) --- the number of test cases.

The first and only line of each test case contains 44 integers a1a1, a2a2, b1b1, b2b2 (1≤a1,a2,b1,b2≤101≤a1,a2,b1,b2≤10) where a1a1 and a2a2 represent the cards Suneet has, and b1b1 and b2b2 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.

Example

Input

Copy

复制代码

5

3 8 2 6

1 1 1 1

10 10 2 2

1 1 10 10

3 8 7 2

Output

Copy

复制代码
2
0
4
0
2

Note

Consider the first test case when Slavic starts with the cards that have the values 22 and 66, and Suneet starts with cards that have the values 33 and 88. The game could happen in 44 different ways:

  • Suneet flips 33 and Slavic flips 22. Suneet wins the first round. Then, Suneet flips 88 and Slavic flips 66. Suneet wins the second round as well. Since Suneet won 22 rounds, he wins the game.

  • Suneet flips 33 and Slavic flips 66. Slavic wins the first round. Then, Suneet flips 88 and Slavic flips 22. Suneet wins the second round. Nobody wins since both players won an equal amount of rounds.

  • Suneet flips 88 and Slavic flips 66. Suneet wins the first round. Then, Suneet flips 33 and Slavic flips 22. Suneet wins the second round as well. Since Suneet won 22 rounds, he wins the game.

  • Suneet flips 88 and Slavic flips 22. Suneet wins the first round. Then, Suneet flips 33 and Slavic flips 66. Slavic wins the round. Nobody wins since both players won an equal amount of rounds.

解题说明:此题是一道模拟题,要求计算出第一个人赢得所有情况,就是两场中至少一平一胜才行。可以直接比较四个数字的大小,进行组合求解。

cpp 复制代码
#include<stdio.h>

int main()
{
	int t, a1, a2, b1, b2;
	scanf("%d", &t);
	for (t; t > 0; t--)
	{
		int q = 0;
		scanf("%d %d %d %d", &a1, &a2, &b1, &b2);
		if ((a1 >= b1 && a2 > b2) || (a1 > b1 && a2 >= b2))
		{
			q++;
		}
		if ((a1 >= b2 && a2 > b1) || (a1 > b2 && a2 >= b1))
		{
			q++;
		}
		printf("%d\n", q * 2);
	}
	return 0;

}
相关推荐
浅念-5 小时前
动态规划专题:斐波那契数列模型 + 网格路径DP(LeetCode例题全解析)
笔记·算法·leetcode·面试·职场和发展·动态规划·推荐算法
一只旭宝6 小时前
数据结构与算法复习手册:从写过,到讲清楚
开发语言·数据结构·c++·算法
夏幻灵6 小时前
每日一题:LeetCode 20:有效的括号——栈与哈希映射详解
算法·leetcode·哈希算法
hetao17338376 小时前
2026-10-07 hetao1733837 的刷题记录
c++·算法
Nil2087 小时前
leetcode 279完全平方数
算法·leetcode·职场和发展
All for pursuit.7 小时前
【动态规划-1】121.买卖股票的最佳时机
数据结构·c++·算法·leetcode·动态规划
名不经传的养虾人7 小时前
从0到1:企业级AI项目迭代日记 Vol.117|学会忘记,学会证明,学会设边界
大数据·人工智能·算法·企业ai·多agent协作
weixin_307779137 小时前
C++代码实现MATLAB中的cvpartition函数功能
开发语言·c++·算法·matlab
(Charon)7 小时前
【C++面试】线程同步机制:互斥锁、条件变量、原子操作与读写锁
开发语言·c++·算法·面试
七牛云行业应用7 小时前
刚刚!GPT-6.1 Sol Ultrafast 上线:速度、价格、API 接入全指南
算法