Codeforce Round #632(Div2)2019/4/9:

A. Little Artem
Young boy Artem tries to paint a picture, and he asks his mother Medina to help him. Medina is very busy, that’s why she asked for your help.

Artem wants to paint an n×m board. Each cell of the board should be colored in white or black.

Lets B be the number of black cells that have at least one white neighbor adjacent by the side. Let W be the number of white cells that have at least one black neighbor adjacent by the side. A coloring is called good if B=W+1.

The first coloring shown below has B=5 and W=4 (all cells have at least one neighbor with the opposite color). However, the second coloring is not good as it has B=4, W=4 (only the bottom right cell doesn’t have a neighbor with the opposite color).

Please, help Medina to find any good coloring. It’s guaranteed that under given constraints the solution always exists. If there are several solutions, output any of them.

Input
Each test contains multiple test cases.

The first line contains the number of test cases t (1≤t≤20). Each of the next t lines contains two integers n,m (2≤n,m≤100) — the number of rows and the number of columns in the grid.
Codeforce Round #632(Div2)2019/4/9:_第1张图片

Output
For each test case print n lines, each of length m, where i-th line is the i-th row of your colored matrix (cell labeled with ‘B’ means that the cell is black, and ‘W’ means white). Do not use quotes.

It’s guaranteed that under given constraints the solution always exists.

Example
inputCopy
2
3 2
3 3
outputCopy
BW
WB
BB
BWB
BWW
BWB
Note
In the first testcase, B=3, W=2.

In the second testcase, B=5, W=4. You can see the coloring in the statement.

题目解析:
既然要求B=W+1,直接构造一个特殊情况,顶角上2个B顶着一个W,这样B=2,W=1。这种让你写出来一种情况的题目,大都是脑筋急转弯,或分析分析就出答案的。

B. Kind Anton
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Once again, Boris needs the help of Anton in creating a task. This time Anton needs to solve the following problem:

There are two arrays of integers a and b of length n. It turned out that array a contains only elements from the set {−1,0,1}.

Anton can perform the following sequence of operations any number of times:

Choose any pair of indexes (i,j) such that 1≤i Add ai to aj. In other words, j-th element of the array becomes equal to ai+aj.
For example, if you are given array [1,−1,0], you can transform it only to [1,−1,−1], [1,0,0] and [1,−1,1] by one operation.

Anton wants to predict if it is possible to apply some number (zero or more) of these operations to the array a so that it becomes equal to array b. Can you help him?

Input
Each test contains multiple test cases.

The first line contains the number of test cases t (1≤t≤10000). The description of the test cases follows.

The first line of each test case contains a single integer n (1≤n≤105) — the length of arrays.

The second line of each test case contains n integers a1,a2,…,an (−1≤ai≤1) — elements of array a. There can be duplicates among elements.

The third line of each test case contains n integers b1,b2,…,bn (−109≤bi≤109) — elements of array b. There can be duplicates among elements.

It is guaranteed that the sum of n over all test cases doesn’t exceed 105.

Output
For each test case, output one line containing “YES” if it’s possible to make arrays a and b equal by performing the described operations, or “NO” if it’s impossible.

You can print each letter in any case (upper or lower).

Example
inputCopy
5
3
1 -1 0
1 1 -2
3
0 1 1
0 2 2
2
1 0
1 41
2
-1 0
-1 -41
5
0 1 -1 1 -1
1 1 -1 1 -1
outputCopy
YES
NO
YES
YES
NO
Note
In the first test-case we can choose (i,j)=(2,3) twice and after that choose (i,j)=(1,2) twice too. These operations will transform [1,−1,0]→[1,−1,−2]→[1,1,−2]
In the second test case we can’t make equal numbers on the second position.

In the third test case we can choose (i,j)=(1,2) 41 times. The same about the fourth test case.

In the last lest case, it is impossible to make array a equal to the array b.

题目解析:
这题大概就是让你在一个只含{0,-1,1}的一个数列里,通过把某一个数ai加到另一个数aj(注意i < j)(这样就使得aj=ai+aj)的方式,来构造出b数列,问你可行还是不可行?从每一个bj的角度分析,有两个想法:1.bj > aj , 那么我们要从aj前面(i 代码实现:
用一个c数组记录前面有-1,1,0的个数,从后往前遍历a数组,(每次c中都会减少一个可用),然后按照刚刚说的,写个if和else if进行判断就行。

你可能感兴趣的:(Codeforce Round #632(Div2)2019/4/9:)