A. Little Artem 链接:TvT
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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×mn×m board. Each cell of the board should be colored in white or black.
Lets BB be the number of black cells that have at least one white neighbor adjacent by the side. Let WW 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+1B=W+1.
The first coloring shown below has B=5B=5 and W=4W=4 (all cells have at least one neighbor with the opposite color). However, the second coloring is not good as it has B=4B=4, W=4W=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 tt (1≤t≤201≤t≤20). Each of the next tt lines contains two integers n,mn,m (2≤n,m≤1002≤n,m≤100) — the number of rows and the number of columns in the grid.
Output
For each test case print nn lines, each of length mm, where ii-th line is the ii-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
input
2
3 2
3 3
output
BW
WB
BB
BWB
BWW
BWB
Note
In the first testcase, B=3B=3, W=2W=2.
In the second testcase, B=5B=5, W=4W=4. You can see the coloring in the statement.
大意:
要构造一个满足B=W+1的emm图(暂且叫图叭..),其中B是周围至少有一个W的B的总数目,W是周围至少有一个B的W的总数目。
思路:
开始上来先大致看了一下题意,然后看了测试样例,理所当然的把B理解成B的数目,W是W的数目了。emm应该好好看要求。其实只要是保证有一个角是W,那么B周围至少有一个W的B的数目就是2,然后W是1,就满足B=W+1了。。然后就没了。。
代码:
#include<stdio.h>
int main()
{
int t;
int n,m;
scanf("%d",&t);
while(t--)
{
scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(i==1&&j==1)
printf("W");
else
printf("B");
}
printf("\n");
}
}
return 0;
}
emm这是cf的第一个题,记录一下8:)
B.Kind Anton 链接:ToT
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard 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 aa and bb of length nn. It turned out that array aa contains only elements from the set {−1,0,1}{−1,0,1}.
Anton can perform the following sequence of operations any number of times:
- Choose any pair of indexes (i,j)(i,j) such that 1≤i<j≤n1≤i<j≤n. It is possible to choose the same pair (i,j)(i,j) more than once.
- Add aiai to ajaj. In other words, jj-th element of the array becomes equal to ai+ajai+aj.
For example, if you are given array [1,−1,0][1,−1,0], you can transform it only to [1,−1,−1][1,−1,−1], [1,0,0][1,0,0] and [1,−1,1][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 aa so that it becomes equal to array bb. Can you help him?
Input
Each test contains multiple test cases.
The first line contains the number of test cases tt (1≤t≤100001≤t≤10000). The description of the test cases follows.
The first line of each test case contains a single integer nn (1≤n≤1051≤n≤105) — the length of arrays.
The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (−1≤ai≤1−1≤ai≤1) — elements of array aa. There can be duplicates among elements.
The third line of each test case contains nn integers b1,b2,…,bnb1,b2,…,bn (−109≤bi≤109−109≤bi≤109) — elements of array bb. There can be duplicates among elements.
It is guaranteed that the sum of nn over all test cases doesn't exceed 105105.
Output
For each test case, output one line containing "YES" if it's possible to make arrays aa and bb equal by performing the described operations, or "NO" if it's impossible.
You can print each letter in any case (upper or lower).
Example
input
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
output
YES
NO
YES
YES
NO
Note
In the first test-case we can choose (i,j)=(2,3)(i,j)=(2,3) twice and after that choose (i,j)=(1,2)(i,j)=(1,2) twice too. These operations will transform [1,−1,0]→[1,−1,−2]→[1,1,−2][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)(i,j)=(1,2) 4141 times. The same about the fourth test case.
In the last lest case, it is impossible to make array aa equal to the array bb.
大意:
有一个数组a,一个数组b,其中数组a中只有-1,0,1三种,有一种操作是这样的:aj=aj+ai(i<j),问可不可以通过这种操作,让a,b数组相同,可以操作无数次。
思路:
a数组倒着遍历,如果ai>bi,看看bi前有没有-1,如果ai<bi,看看ai前有没有1,有就可以,没有就不可以。