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. Java基础概念性问题整理,面试题型整理,附带答案详解供参考,首次整理!

    题目目录 Java基础 1.JDK1.8新特性? 2.面向对象和面向过程的区别? 3.什么是值传递和引用传递? 4.什么是不可变对象? 5.讲讲类的实例化顺序? 6.java 创建对象的几种方式 7. ...

  2. Java开发手册之编程规约

    时隔一年多,再次开始更新博客,各位粉丝们久等了.大家是不是以为我像大多数开发者一样三分钟热度,坚持了一年半载就放弃了,其实不是.在过去的一年时间我学习了<Java编程思想>这本书,因为都是 ...

  3. MySQL select 查询之分组和过滤

    SELECT 语法 SELECT [ALL | DISTINCT] {* | table.* | [table.field1[as alias1][,table.field2[as alias2]][ ...

  4. 【ORA】ORA-00371: not enough shared pool memory

    今天rac中有一个节点asm实例起不来包了ora-000371的错误,错误贴在下面: [oracle@rac2 dbs]$ srvctl start asm -n rac2 PRKS-1009 : F ...

  5. Apache目录详解

    Apache的主要目录和配置文件理解 参考链接:http://httpd.apache.org/docs/2.4/misc/security_tips.html 一.Apache主要配置文件注释(演示 ...

  6. mysql查看修改参数

    1.查看参数 show variables like '%timeout%'; 2.修改参数 会话级别修改: set session innodb_lock_wait_timeout=50; 对当前会 ...

  7. Jquery实现对Array数组实现类似Linq的Lambda表达式的Where方法筛选

    平时使用Linq,习惯了Lambda表达式,用着非常顺手,奈何在Jquery里面不能这样用,只能循环一个个判断.趁空闲时间找了找,自己写了这样的扩展方法.目前写出了三种方案,没有比较性能,觉得都可以用 ...

  8. Ice系列--傻瓜式服务开发IceBox

    前言 相信大家在没有接触过框架之前,都自己或多或少的开发过一些应用服务.每个应用服务除了业务配置还有很多环境配置,资源配置等,这些跟部署相关的配置.服务跟配置文件是一种静态绑定的方式,更新配置还需要重 ...

  9. 一文读懂 TKE 及 Kubernetes 访问权限控制

    你有了解过Kubernetes的认证授权链路吗?是否对TKE的权限控制CAM策略.服务角色傻傻分不清楚?本文将会向你介绍腾讯云TKE平台侧的访问控制.Kubernetes访问控制链路,以及演示如何将平 ...

  10. Python设计模式面向对象编程

    前言   本篇文章是基于极客时间王争的<设计模式之美>做的总结和自己的理解.  说到面向对象编程,作为一个合格的Pythoner,可以说信手拈来.毕竟在Python里"万物都是对 ...