CF1499A.Domino on Windowsill

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have a board represented as a grid with 2×n2 \times n cells.

The first k1k_1 cells on the first row and first k2k_2 cells on the second row are colored in white. All other cells are colored in black.

You have ww white dominoes (2×12 \times 1 tiles, both cells are colored in white) and bb black dominoes (2×12 \times 1 tiles, both cells are colored in black).

You can place a white domino on the board if both board's cells are white and not occupied by any other domino. In the same way, you can place a black domino if both cells are black and not occupied by any other domino.

Can you place all w+bw + b dominoes on the board if you can place dominoes both horizontally and vertically?

你有一个由 2×n2 \times n 个格子组成的棋盘。

第一行的前 k1k_1 个格子和第二行的前 k2k_2 个格子被涂成白色,其余所有格子均被涂成黑色。

你有 ww 个白骨牌(2×12 \times 1 的方块,其覆盖的两个格子均为白色)和 bb 个黑骨牌(2×12 \times 1 的方块,其覆盖的两个格子均为黑色)。

当且仅当骨牌所覆盖的两个棋盘格子均为白色且均未被其他骨牌占据时,你才能在棋盘上放置一个白骨牌;同理,当且仅当骨牌所覆盖的两个棋盘格子均为黑色且均未被其他骨牌占据时,你才能在棋盘上放置一个黑骨牌。

若允许骨牌水平或垂直放置,你能否将全部 w+bw + b 个骨牌都放置到棋盘上?

输入格式

The first line contains a single integer tt (1≤t≤30001 \le t \le 3000) — the number of test cases.

The first line of each test case contains three integers nn, k1k_1 and k2k_2 (1≤n≤10001 \le n \le 1000; 0≤k1,k2≤n0 \le k_1, k_2 \le n).

The second line of each test case contains two integers ww and bb (0≤w,b≤n0 \le w, b \le n).

第一行包含一个整数 tt(1≤t≤30001 \le t \le 3000)—— 测试用例的数量。

每个测试用例的第一行包含三个整数 nn、k1k_1 和 k2k_2(1≤n≤10001 \le n \le 1000;0≤k1,k2≤n0 \le k_1, k_2 \le n)。

每个测试用例的第二行包含两个整数 ww 和 bb(0≤w,b≤n0 \le w, b \le n)。

输出格式

For each test case, print YES if it's possible to place all w+bw + b dominoes on the board and NO, otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).

对于每个测试用例,如果可以将全部 w+bw + b 个多米诺骨牌放置在棋盘上,则输出 YES;否则输出 NO。

你可以以任意大小写形式输出每个字母(例如,字符串 yEs、yes、Yes 和 YES 均被视为肯定回答)。

输入输出样例

  • 输入#1

    5
    1 0 1
    1 0
    1 1 1
    0 0
    3 0 0
    1 3
    4 3 1
    2 2
    5 4 3
    3 1

    输出#1

    NO
    YES
    NO
    YES
    YES

说明/提示

In the first test case, n=1n = 1, k1=0k_1 = 0 and k2=1k_2 = 1. It means that 2×12 \times 1 board has black cell (1,1)(1, 1) and white cell (2,1)(2, 1). So, you can't place any white domino, since there is only one white cell.

In the second test case, the board of the same size 2×12 \times 1, but both cell are white. Since w=0w = 0 and b=0b = 0, so you can place 0+0=00 + 0 = 0 dominoes on the board.

In the third test case, board 2×32 \times 3, but fully colored in black (since k1=k2=0k_1 = k_2 = 0), so you can't place any white domino.

In the fourth test case, cells (1,1)(1, 1), (1,2)(1, 2), (1,3)(1, 3), and (2,1)(2, 1) are white and other cells are black. You can place 22 white dominoes at positions ((1,1),(2,1))((1, 1), (2, 1)) and ((1,2),(1,3))((1, 2), (1, 3)) and 22 black dominoes at positions ((1,4),(2,4))((1, 4), (2, 4)) ((2,2),(2,3))((2, 2), (2, 3)).

在第一个测试用例中,n=1n = 1,k1=0k_1 = 0 且 k2=1k_2 = 1。这意味着 2×12 \times 1 的棋盘上,黑色格子为 (1,1)(1, 1),白色格子为 (2,1)(2, 1)。因此,你无法放置任何白色多米诺骨牌,因为白色格子只有一个。

在第二个测试用例中,棋盘大小同样为 2×12 \times 1,但两个格子均为白色。由于 w=0w = 0 且 b=0b = 0,因此你可以在棋盘上放置 0+0=00 + 0 = 0 个多米诺骨牌。

在第三个测试用例中,棋盘大小为 2×32 \times 3,但全部格子均被染成黑色(因为 k1=k2=0k_1 = k_2 = 0),因此你无法放置任何白色多米诺骨牌。

在第四个测试用例中,格子 (1,1)(1, 1)、(1,2)(1, 2)、(1,3)(1, 3) 和 (2,1)(2, 1) 为白色,其余格子为黑色。你可以在位置 ((1,1),(2,1))((1, 1), (2, 1)) 和 ((1,2),(1,3))((1, 2), (1, 3)) 放置 22 个白色多米诺骨牌,并在位置 ((1,4),(2,4))((1, 4), (2, 4)) 和 ((2,2),(2,3))((2, 2), (2, 3)) 放置 22 个黑色多米诺骨牌。

输入解题思路,AI测评打分。不知道怎么写?

首页