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;

}
相关推荐
杨航 AI18 分钟前
** AI 面试算法 50 题清单**,不是单纯的 LeetCode 题号列表,而是按照“**考察概率 × 面试价值 × 你当前准备方向**”排序
算法·leetcode·面试
m0_720245017 小时前
1543.统计好三元组(简单)
开发语言·算法
To_OC7 小时前
LC 560 和为 K 的子数组:前缀和配哈希表,这对组合我是真的服了
javascript·算法·程序员
hans汉斯8 小时前
《软件工程与应用》期刊推荐&10月版面征稿中
图像处理·人工智能·深度学习·算法·音视频·软件工程
叠层归一研究院8 小时前
AGI 系统(八):符号范畴嵌入函子 — SymCat ↪ C_M107 严格化
c语言·开发语言·人工智能·算法·transformer·agi
其美杰布-富贵-李9 小时前
08 进阶评估指标与算法特定指标
人工智能·算法
.道阻且长.10 小时前
5.LeetCode算法习题讲解--双指针--有效三角形的个数
算法·leetcode·职场和发展
我是海飞10 小时前
杰理JL703N SSD1306 OLED(128x64) 点阵屏移植说明
单片机·算法·嵌入式·音频·杰理
wabs66611 小时前
关于图论【最短路径之Bellman_ford 算法(单源有限最短路)|卡码网96.城市间货物运输III的思考】
数据结构·算法·图论·卡码网·bellman_ford·单源有限最短路
lsylalalala13 小时前
常见的排序算法1
数据结构·算法·排序算法