A. Find Square
time limit per test:

1 second

memory limit per test:

256 megabytes

input:

standard input

output:

standard output

Consider a table of size n×mn×m, initially fully white. Rows are numbered 11 through nn from top to bottom, columns 11 through mm from left to right. Some square inside the table with odd side length was painted black. Find the center of this square.

Input

The first line contains two integers nn and mm (1≤n,m≤1151≤n,m≤115) — the number of rows and the number of columns in the table.

The ii-th of the next nn lines contains a string of mm characters si1si2…simsi1si2…sim (sijsij is 'W' for white cells and 'B' for black cells), describing the ii-th row of the table.

Output

Output two integers rr and cc (1≤r≤n1≤r≤n, 1≤c≤m1≤c≤m) separated by a space — the row and column numbers of the center of the black square.

Examples
input
5 6
WWBBBW
WWBBBW
WWBBBW
WWWWWW
WWWWWW

output

2 4

input

3 3
WWW
BWW
WWW

output

2 1

Solution1:

#include <iostream>
const int N = 712;
char maze[N][N];
int a, b, r, c, n;
using namespace std;
void dfs(int i, int k)
{
if (maze[i][k] == 'W') maze[i][k] = 'w';
else
{
r += i, c += k; n += 1;
maze[i][k] = 'b';
}
for (int j = 0; j < b; j++)
if (maze[i][j] == 'W' || maze[i][j] == 'B')
dfs(i, j);
}
int main()
{
scanf_s("%d %d", &a, &b);
r = c = n = 0;
for (int i = 0; i < a; i++)
for (int j = 0; j < b; j++)
cin >> maze[i][j];
for (int i = 0; i < a; i++)
if (maze[i][0] == 'W' || maze[i][0] == 'B')
dfs(i, 0); if (n != 0)
{
r /= n, c /= n;
printf("%d %d\n", r + 1, c + 1);
}
return 0;
}

Solution2:

#include <iostream>
const int N = 712;
char maze[N][N];
int a, b, r, c, n;
using namespace std;
int main()
{
r = c = n = 0;
scanf_s("%d %d", &a, &b);
for (int i = 0; i < a; i++)
for (int j = 0; j < b; j++)
{
cin >> maze[i][j];
if (maze[i][j] == 'B')
r += i, c += j, n += 1;
}
if (n != 0)
{
r /= n, c /= n;
printf("%d %d\n", r + 1, c + 1);
}
return 0;
}

  

  

Codeforces AIM Tech Round 5 (rated, Div. 1 + Div. 2)的更多相关文章

  1. Codeforces AIM Tech Round (Div. 2)

    这是我第一次完整地参加codeforces的比赛! 成绩 news standings中第50. 我觉这个成绩不太好.我前半小时就过了前三题,但后面的两题不难,却乱搞了1.5h都没有什么结果,然后在等 ...

  2. AIM Tech Round 5 (rated, Div. 1 + Div. 2) (A, B, E)

    B.Unnatural Conditions 题目链接 : http://codeforces.com/contest/1028/problem/B #include<iostream> ...

  3. AIM Tech Round 5 (rated, Div. 1 + Div. 2) C. Rectangles 【矩阵交集】

    题目传传传送门:http://codeforces.com/contest/1028/problem/C C. Rectangles time limit per test 2 seconds mem ...

  4. 【Codeforces AIM Tech Round 4 (Div. 2) C】

    ·将排序限制于子序列中,又可以说明什么呢? C. Sorting by Subsequences ·英文题,述大意:       输入一个长度为n的无重复元素的序列{a1,a2……an}(1<= ...

  5. AIM Tech Round 5 (rated, Div. 1 + Div. 2)

    A. Find Square 找到对角线的两个点的坐标,这道题就迎刃而解了. inline void work(int n) { int m; cin >> m; memset(str, ...

  6. AIM Tech Round 5 (rated, Div. 1 + Div. 2) E(思维,构造)

    #include<bits/stdc++.h>using namespace std;long long a[150007];long long ans[150007];int main( ...

  7. AIM Tech Round 5 (rated, Div. 1 + Div. 2) D(SET,思维)

    #include<bits/stdc++.h>using namespace std;const long long mod = 1e9+7;char s[370007][27];long ...

  8. codeforces AIM Tech Round 4 div 2

    A:开个桶统计一下,但是不要忘记k和0比较大小 #include<bits/stdc++.h> using namespace std; ]; ]; int main() { int k; ...

  9. 【AIM Tech Round 5 (rated, Div. 1 + Div. 2) 总结】【题解往前或往后翻,不在这】

    又是爆炸的一场 心态有点小崩.但问题不大.. 看A题,一直担心有多个正方形..小心翼翼地看完之后,毅然地交上去了. [00:08] A[Accpted] 然后开始看B题. 觉得和之前做的某题很像,但翻 ...

随机推荐

  1. jmeter 登陆--查询存在否-->新建客户-->查询存在否 + 压测

    1.登陆 正则表达式提取器和json提取器,都是后置处理器提取token(都可以在响应中以regexp tester 和 json path tester查看提取的对不对) beanshell 后置处 ...

  2. APP开发工具如何选?

    随着技术的发展,在当前开发一款APP已经非常的简单和快速.特别是近些年,利用HTML5技术将APP的开发门槛进一步降低.各种开发工具和框架层出不穷,令人眼花缭乱.这么多的工具摆在眼前应该如何进行选择呢 ...

  3. Git 添加远程github仓库的时候提示错误:fatal: remote origin already exists.

    1.先删除远程 Git 仓库 $ git remote rm origin 2.再添加远程 Git 仓库 $ git remote add origin git@github.com:wsydxian ...

  4. 通过属性选择器找元素,可以通过$(__).length是否为0来判断是否找到了元素

    通过属性选择器找元素,可以通过$("").length是否为0来判断是否找到了元素. 为0的时候表示没有找到,其余则返回找到了多少个. 不能通过$("")是否为 ...

  5. 第四十七篇 入门机器学习——分类的准确性(Accuracy)

    No.1. 通常情况下,直接将训练得到的模型应用于真实环境中,可能会存在很多问题 No.2. 比较好的解决方法是,将原始数据中的大部分用于训练数据,而留出少部分数据用于测试,即,将数据集切分成训练数据 ...

  6. 用python脚本测试接口

    自己写一个脚本,统计调用200次接口的请求时长. # -*- coding=utf-8 -*-import osimport requestsimport time url = "http: ...

  7. js获取后台map格式数据

    后台: @RequestMapping("/dictList") @ResponseBody public Map<String, Object> positionLi ...

  8. Apache Kafka(八)- Kafka Delivery Semantics for Consumers

    Kafka Delivery Semantics 在Kafka Consumer中,有3种delivery semantics,分别为:至多一次(at most once).至少一次(at least ...

  9. 阻塞队列BlockingQueue之ArrayBlockingQueue

    ArrayBlockingQueue  是数组实现的有界阻塞队列,此队列按照先进先出(FIFO)的原则对元素进行排序. 构造方法: public ArrayBlockingQueue(int capa ...

  10. go基础_定时器

    每间隔5s打印一句hello // time_ticker package main import ( "fmt" "time" ) func main() { ...