第四周周记

Card Game

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.

Suneet 和Slavic玩纸牌游戏。游戏规则如下

  • 每张牌的整数值介于 11 和 1010 之间。
  • 每位玩家收到的 22 张牌都是面朝下的(所以玩家不知道自己的牌)。
  • 游戏采用回合制,由个回合组成。在一个回合中,双方随机抽取一张未翻开的牌并翻开。翻开的牌中数字严格意义上更大的一方获胜。如果数字相等,则无人获胜。
  • 如果一名玩家赢得的回合数最多(即严格意义上大于另一名玩家),则该玩家赢得游戏。如果相等,则无人获胜。

由于 Suneet 和 Slavic 并不是最好的朋友,您需要计算 Suneet 最终成为赢家的可能性有多少。

为了更好地理解,请查看注释部分。

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.

输入

第一行包含一个整数 t ( 1≤t≤10^4 ) - 测试用例的数量。

每个测试用例的第一行也是唯一一行包含 4 个整数 a1、 a2、 b1 、 b2 ( 1≤a1,a2,b1,b2≤10 ),其中 a1 和 a2 分别代表 Suneet 拥有的卡片, b1 和 b2 分别代表 Slavic 拥有的卡片。

Output

For each test case, output a single integer — the number of games Suneet would win considering all possible games.

输出

对于每个测试案例,输出一个整数--考虑到所有可能的游戏,Suneet 会赢的游戏数量。

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
#include <stdio.h>

int main() {
    int t;
    scanf("%d", &t);
    
    while(t--) {
        int a1, a2, b1, b2;
        scanf("%d %d %d %d", &a1, &a2, &b1, &b2);
        
        int sw = 0;
        int oc[4][4] = {
            {a1, b1, a2, b2},
            {a1, b2, a2, b1},
            {a2, b1, a1, b2},
            {a2, b2, a1, b1}
        };
        
        for (int i = 0; i < 4; i++) {
            int sr = 0, sl = 0;
            if (oc[i][0] > oc[i][1]) sr++;
            if (oc[i][0] < oc[i][1]) sl++;
            if (oc[i][2] > oc[i][3]) sr++;
            if (oc[i][2] < oc[i][3]) sl++;
            
            if (sr > sl) sw++;
        }
        
        printf("%d\n", sw);
    }
    
    return 0;
}

Balls and Bag Query

Problem Statement

You have an empty bag. You are given Q queries, which must be processed in order.

There are three types of queries.

1 x : Put one ball with the integer x written on it into the bag.

2 x : Remove one ball with the integer x written on it from the bag and discard it. It is guaranteed that the bag has a ball with the integer x written on it when this query is given.

3 : Print the number of different integers written on the balls in the bag.

Constraints

1≤Q≤2×10^5

1≤x≤10^6

When a query of the second type is given, the bag has a ball with the integer x written on it.

There is at least one query of the third type.

All input values are integers.

Input

The input is given from Standard Input in the following format:

Q
query1
query2​
⋮
queryQ

The ii-th query queryiqueryi​ is given in one of the following three formats:

1 x
2 x
3

 

Output

If there are K queries of the third type, print K lines. The i-th line (1≤i≤K)should contain the answer to the i-th query of the third type.

题目大意

你有一个空袋子。给你 QQ 个查询,必须按顺序处理。

查询有三种类型。

  • 1 x : 将一个写有整数 xx 的球放入袋子中。
  • 2 x :从袋子中取出一个写有整数 xx 的球并丢弃。当给出这个查询时,可以保证袋子中有一个写着整数 xx 的球。
  • 3 : 打印袋中写有不同整数的球的个数。

 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_X 1000000
int main() {
    int Q;
    scanf("%d",&Q);
    int *c= (int *)calloc(MAX_X + 1, sizeof(int));
    int dc = 0;
    while (Q--) {
        int t, x;
        scanf("%d", &t);
        if (t == 1) {
            scanf("%d", &x);
            if (c[x] == 0) {
                dc++;
            }
            c[x]++;
        } else if (t == 2) {
            scanf("%d", &x);
            c[x]--;
            if (c[x] == 0) {
                dc--;
            }
        } else if (t == 3) {
            printf("%d\n", dc);
        }
    }
    free(c);
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值