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×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 

题意:给你一个n*m的矩阵,(2<=n,m<=100),要求你涂色,记W是四周至少有一个黑色方块的白色方块,B是四周至少有一个白色方块的黑色方块,如果B=W+1,那这个涂色方案就是好的,求怎么涂才能变成好的

题解:因为矩阵至少是2X2的,所以没必要特判,随便让四个角之一的格子变成白的,其他都是黑色即可

代码:

 1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <cmath>
5 #include <algorithm>
6 #include <stack>
7 #include <queue>
8 #include <vector>
9 #include <map>
10 #include <set>
11 #include <unordered_set>
12 #include <unordered_map>
13 #define ll long long
14 #define fi first
15 #define se second
16 #define pb push_back
17 #define me memset
18 const int N = 1e6 + 10;
19 const int mod = 1e9 + 7;
20 using namespace std;
21 typedef pair<int,int> PII;
22 typedef pair<long,long> PLL;
23 int t;
24 int n,m;
25 int main() {
26 ios::sync_with_stdio(false);
27 cin>>t;
28 while(t--){
29 cin>>n>>m;
30 for(int i=1;i<=n;++i) {
31 for (int j=1;j<=m;++j) {
32 if (i ==1&&j==m) printf("W");
33 else printf("B");
34 }
35 printf("\n");
36 }
37 }
38
39 return 0;
40 }
                              B. Kind Anton
 

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:

  1. 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.
  2. 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

题意:给你一个长度为n的数组a和b,a只包含-1,0,1,对于i<j,有a[j]=a[j]+a[i],问能通过这样的操作将数组a变成数组b
题解:首先假如a[1]!b[1],直接输出NO,(假如不这样可能会T?),然后倒着遍历b,假如b[i]>a[i],那就必须要在i前面找a[i]==1,同理假如b[i]<a[i],就要找a[i]==-1.
代码:
 1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <cmath>
5 #include <algorithm>
6 #include <stack>
7 #include <queue>
8 #include <vector>
9 #include <map>
10 #include <set>
11 #include <unordered_set>
12 #include <unordered_map>
13 #define ll long long
14 #define fi first
15 #define se second
16 #define pb push_back
17 #define me memset
18 const int N = 1e6 + 10;
19 const int mod = 1e9 + 7;
20 using namespace std;
21 typedef pair<int,int> PII;
22 typedef pair<long,long> PLL;
23
24 int t;
25 int n,a[N],b[N];
26
27 int main() {
28 ios::sync_with_stdio(false);
29 cin>>t;
30 while(t--){
31 cin>>n;
32 for(int i=0;i<n;++i) cin>>a[i];
33 for(int i=0;i<n;++i) cin>>b[i];
34
35 if(a[0]!=b[0]){
36 printf("NO\n");
37 continue;
38 }
39 if(n==1 && a[0]==b[0]){
40 printf("YES\n");
41 continue;
42 }
43 bool flag=0;
44 for(int i=n-1;i>=1;--i){
45 flag=0;
46 if(b[i]==a[i]){
47 flag=1;
48 continue;
49 }
50 else if(b[i]<a[i]){
51 for(int j=0;j<i;++j){
52 if(a[j]==-1){
53 flag=1;
54 break;
55 }
56 }
57 }
58 else if(b[i]>a[i]){
59 for(int j=0;j<i;++j){
60 if(a[j]==1){
61 flag=1;
62 break;
63 }
64 }
65 }
66 if(flag==0) break;
67 }
68 if(flag) printf("YES\n");
69 else printf("NO\n");
70 }
71
72 return 0;
73 }
                            C. Eugene and an array
 

Eugene likes working with arrays. And today he needs your help in solving one challenging task.

An array cc is a subarray of an array bb if cc can be obtained from bb by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

Let's call a nonempty array good if for every nonempty subarray of this array, sum of the elements of this subarray is nonzero. For example, array [−1,2,−3][−1,2,−3] is good, as all arrays [−1][−1], [−1,2][−1,2], [−1,2,−3][−1,2,−3], [2][2], [2,−3][2,−3], [−3][−3] have nonzero sums of elements. However, array [−1,2,−1,−3][−1,2,−1,−3] isn't good, as his subarray [−1,2,−1][−1,2,−1] has sum of elements equal to 00.

Help Eugene to calculate the number of nonempty good subarrays of a given array aa.

Input

The first line of the input contains a single integer nn (1≤n≤2×1051≤n≤2×105)  — the length of array aa.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (−109≤ai≤109−109≤ai≤109)  — the elements of aa.

Output

Output a single integer  — the number of good subarrays of aa.

Examples
input
3
1 2 -3
output
5
input
3
41 -41 41
output
3
题意:给你一个数组,求元素和不等于0的连续子数组有多少个.
题解:对数组的每一个位置求前缀和s,假如si==sj,那么ai+1+.....aj=0,所以我们就不要考虑i+1之前的数了(子数组的子数组中也不能为0),用一个map来存前缀和的位置,遍历一边前缀和,可以理解为每次从该位置开始向左找,如果找到第一个与它相等的值,我们就记录这个区间的长度,
用代码来表示就是,假如在当前位置之前有与它相等的前缀和,那么我们就选择距离当前位置最近的那个(子数组的子数组中也不能为0),记录这个区间的长度即可
 1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <cmath>
5 #include <algorithm>
6 #include <stack>
7 #include <queue>
8 #include <vector>
9 #include <map>
10 #include <set>
11 #include <unordered_set>
12 #include <unordered_map>
13 #define ll long long
14 #define fi first
15 #define se second
16 #define pb push_back
17 #define me memset
18 const int N = 1e6 + 10;
19 const int mod = 1e9 + 7;
20 using namespace std;
21 typedef pair<int,int> PII;
22 typedef pair<long,long> PLL;
23
24 int n;
25 ll a[N];
26 map<ll,ll> mp;
27
28 int main() {
29 ios::sync_with_stdio(false);
30 cin>>n;
31 for(int i=1;i<=n;++i) cin>>a[i];
32
33 ll ans=0,sum=0,pos=0;
34 mp[0]=1;
35 for(int i=1;i<=n;++i){
36 sum+=a[i];
37 if(mp[sum]) pos=max(pos,mp[sum]);
38 ans+=i-pos;
39 mp[sum]=i+1;
40 }
41 printf("%lld\n",ans);
42
43 return 0;
44 }


Codeforces #Round 632 div2 A~C的更多相关文章

  1. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  2. 【前行】◇第3站◇ Codeforces Round #512 Div2

    [第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...

  3. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  4. Codeforces Round #564(div2)

    Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...

  5. Codeforces Round #632 (Div. 2)

    Codeforces Round #632 (Div. 2) 这一场打的好差呀,这几次艰难上的分全部掉回去了,感觉就像一夜回到了解放前. 说实话,就是被B卡到了,没看到只能从小的放到大的... Lit ...

  6. Codeforces Round #361 div2

    ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...

  7. Codeforces Round #626 Div2 D,E

    比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...

  8. CodeForces Round 192 Div2

    This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...

  9. Codeforces Round #359 div2

    Problem_A(CodeForces 686A): 题意: \[ 有n个输入, +\space d_i代表冰淇淋数目增加d_i个, -\space d_i表示某个孩纸需要d_i个, 如果你现在手里 ...

随机推荐

  1. AI智能皮肤测试仪助力美业数字化营销 实现门店与用户双赢局面

    当皮肤遇到AI智能,会有怎么样的火花呢?随着生活水平的提升,人们对肌肤保养护理的需求也越来越高,人要美,皮肤养护也要更精准,数字化必将成为美业发展的新契机.新机遇下肌肤管家SkinRun为美业客户提供 ...

  2. 用js实现打印九九乘法表

    用js在打印九九乘法表 思考 在学习了流程控制和条件判断后,我们可以利用js打印各式各样的九九乘法表 不管是打印什么样三角形九九乘法表,我们都应该找到有规律的地方,比如第一列的数字是什么规律,第一行的 ...

  3. requests +httprunne r

    1.get 请求和 post 请求的区别是什么?  2.requests 模拟 get 请求时,有哪两种方式让响应的结果不是乱码?(直接代码描述)  3.requests 库中的 post 方法,参数 ...

  4. 入门OJ:简单的网络游戏

    题目描述 在某款极具技术含量的网络游戏中,佳佳靠着他的聪明智慧垄断了游戏中的油田系统.油田里有许多油井,这些油井排成一个M*N的矩形.每个油井都有一个固定的采油量.每两个相邻的油井之间有一条公路,这些 ...

  5. three.js cannon.js物理引擎之Heightfield

    今天郭先生说一说cannon.js物理引擎之Heightfield高度场,学过场论的朋友都知道物理学中把某个物理量在空间的一个区域内的分布称为场,高度场就是与高度相关的场,而cannon.js物理引擎 ...

  6. java实现Excel定制导出(基于POI的工具类)

    我的需求: 项目中有一些工程表格需要导出,设计到行列合并,定制样式,原有工具类冗余,内聚性强.所以想写一个可以随意定制excel的工具类,工具类满足需求: 对于常用的工程表格有模板格式,可以任意插拔. ...

  7. 温习数据算法—js滑块验证码

    前言 大多数的应用软件都需要输入一些验证码,验证码的样式也多种多样. 比如抢票,提交订单需要验证码,很多人就纳闷了,怎么还需要验证码呢?这不是浪费时间嘛. 存在即合理,合理就是现实的. 源码下载地址+ ...

  8. OAuth2.0是干什么的?

    OAuth2.0是干什么的? 首先用户有一些数据: 将数据存储在服务器上: 这时候有一个应用要访问数据: 如果这个应用是一个恶意程序呢?所以需要一个检验来判断请求是不是安全的: 如何判断是不是安全的? ...

  9. leaving sockets open which can trigger a ResourceWarning in some # cases, and look like a memory leak in others

    # -*- coding: utf-8 -*- """ requests.api ~~~~~~~~~~~~ This module implements the Requ ...

  10. the code has to work especially hard to keep things in the same thread

    django/asgiref: ASGI specification and utilities https://github.com/django/asgiref/