CF1196E.Connected Component on a Chessboard
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two integers b and w. You have a chessboard of size 109×109 with the top left cell at (1;1), the cell (1;1) is painted white.
Your task is to find a connected component on this chessboard that contains exactly b black cells and exactly w white cells. Two cells are called connected if they share a side (i.e. for the cell (x,y) there are at most four connected cells: (x−1,y),(x+1,y),(x,y−1),(x,y+1)). A set of cells is called a connected component if for every pair of cells C1 and C2 from this set, there exists a sequence of cells c1, c2, ..., ck such that c1=C1, ck=C2, all ci from 1 to k are belong to this set of cells and for every i∈[1,k−1], cells ci and ci+1 are connected.
Obviously, it can be impossible to find such component. In this case print "NO". Otherwise, print "YES" and any suitable connected component.
You have to answer q independent queries.
给你两个整数 b 和 w。你拥有一块大小为 109×109 的国际象棋棋盘,其左上角格子坐标为 (1,1),且格子 (1,1) 为白色。
你的任务是在该棋盘上找出一个连通块,使得其中恰好包含 b 个黑色格子和 w 个白色格子。若两个格子有公共边,则称它们是相连的(即:对于格子 (x,y),最多有四个与其相连的格子:(x−1,y), (x+1,y), (x,y−1), (x,y+1))。一个格子集合被称为连通块,当且仅当对该集合中任意两个格子 C1 和 C2,均存在一个格子序列 c1,c2,…,ck,满足:c1=C1,ck=C2,所有 ci(i=1 到 k)均属于该集合,且对每个 i∈[1,k−1],格子 ci 与 ci+1 相连。
显然,有时可能无法找到满足条件的连通块。此时请输出 "NO"。否则,请输出 "YES",并给出任意一个符合条件的连通块。
你需要回答 q 个相互独立的查询。
输入格式
The first line of the input contains one integer q (1≤q≤105) — the number of queries. Then q queries follow.
The only line of the query contains two integers b and w (1≤b,w≤105) — the number of black cells required and the number of white cells required.
It is guaranteed that the sum of numbers of cells does not exceed 2⋅105 (∑w+∑b≤2⋅105).
输入的第一行包含一个整数 q(1≤q≤105),表示查询次数。接下来是 q 次查询。
每次查询仅包含一行,其中有两个整数 b 和 w(1≤b,w≤105),分别表示所需黑格子的数量和白格子的数量。
保证所有查询中格子总数之和不超过 2⋅105(即 ∑w+∑b≤2⋅105)。
输出格式
For each query, print the answer to it.
If it is impossible to find the required component, print "NO" on the first line.
Otherwise, print "YES" on the first line. In the next b+w lines print coordinates of cells of your component in any order. There should be exactly b black cells and w white cells in your answer. The printed component should be connected.
If there are several answers, you can print any. All coordinates in the answer should be in the range [1;109].
对于每个查询,请输出该查询的答案。
如果无法找到满足要求的连通块,则在第一行输出 "NO"。
否则,在第一行输出 "YES";接下来的 b+w 行中,以任意顺序输出你所选连通块中各格子的坐标。你的答案中必须恰好包含 b 个黑格和 w 个白格,且所输出的连通块必须是连通的。
若存在多个合法答案,输出任意一个即可。答案中所有坐标的取值范围均需在 [1;109] 内。
输入输出样例
输入#1
3 1 1 1 4 2 5
输出#1
YES 2 2 1 2 YES 2 3 1 3 3 3 2 2 2 4 YES 2 3 2 4 2 5 1 3 1 5 3 3 3 5
输入解题思路,AI测评打分。不知道怎么写?