Codeforces AIM Tech Round 5 (rated, Div. 1 + Div. 2)
1 second
256 megabytes
standard input
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.
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 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.
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)的更多相关文章
- Codeforces AIM Tech Round (Div. 2)
这是我第一次完整地参加codeforces的比赛! 成绩 news standings中第50. 我觉这个成绩不太好.我前半小时就过了前三题,但后面的两题不难,却乱搞了1.5h都没有什么结果,然后在等 ...
- AIM Tech Round 5 (rated, Div. 1 + Div. 2) (A, B, E)
B.Unnatural Conditions 题目链接 : http://codeforces.com/contest/1028/problem/B #include<iostream> ...
- 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 ...
- 【Codeforces AIM Tech Round 4 (Div. 2) C】
·将排序限制于子序列中,又可以说明什么呢? C. Sorting by Subsequences ·英文题,述大意: 输入一个长度为n的无重复元素的序列{a1,a2……an}(1<= ...
- AIM Tech Round 5 (rated, Div. 1 + Div. 2)
A. Find Square 找到对角线的两个点的坐标,这道题就迎刃而解了. inline void work(int n) { int m; cin >> m; memset(str, ...
- 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( ...
- 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 ...
- codeforces AIM Tech Round 4 div 2
A:开个桶统计一下,但是不要忘记k和0比较大小 #include<bits/stdc++.h> using namespace std; ]; ]; int main() { int k; ...
- 【AIM Tech Round 5 (rated, Div. 1 + Div. 2) 总结】【题解往前或往后翻,不在这】
又是爆炸的一场 心态有点小崩.但问题不大.. 看A题,一直担心有多个正方形..小心翼翼地看完之后,毅然地交上去了. [00:08] A[Accpted] 然后开始看B题. 觉得和之前做的某题很像,但翻 ...
随机推荐
- Binary Number(位运算)
#include<bits/stdc++.h> using namespace std; int n; int getBits1(int n)//求取一个数的二进制形式中1的个数. { i ...
- 使用Powershell开机启动隐藏窗口的程序
1.打开注册表找到键值:计算机\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run 2.添加字符串值:StartJetSer ...
- 1.什么是springboot
什么是spring? Spring是一个开源框架,2003 年兴起的一个轻量级的Java 开发框架,作者:Rod Johnson . Spring是为了解决企业级应用开发的复杂性而创建的,简化开发. ...
- 字符串判空有空格报错:binary operator expected
使用-z或-n对一个变量判空时,需要注意若直接使用[ -n ${ARG} ]这种形式,若${ARG}中有空格将会报错, #!/bin/bash ARG="sd dd" if [ - ...
- jQuery对象和语法
jQuery类型 引入jquery.js时,其实是向全局作用域中,添加了一个新的类型--jQuery. 构造函数:负责创建jQuery类型的对象. 原型对象:保存jQuery对象可用的所有简化版API ...
- 网页格式gbk转utf-8【python requests】
resp = requests.get(url) resp.content 是str类型 resp.text是unicode类型 如果返回的中文使用gbk编码,需要转换成utf-8的时候: resp. ...
- window10 上的mysql8.0.13的数据库服务丢失后,找回方法
1.由于mysql8 的 话是默认有一个配置文件的,所以在执行 初始化mysql8 mysqld --initialize #执行这个的原因是:因为之前使用的是Mysql8中自带的那个默认的配置文件 ...
- Nginx的相关介绍
前言 说到服务器,一定会想到apache的httpd和Nginx Apache的发展时期很长,而且是毫无争议的世界第一大服务器.它有着很多优点:稳定.开源.跨平台等等.它出现的时间太长了,它兴起的年代 ...
- html()和append()
html()方法会替换原有内容,append() 方法在被选元素的结尾插入指定内容.prepend() 方法在被选元素的开头插入指定内容 appendChild() 方法向节点添加最后一个子节点.pr ...
- 【转】解决jenkins自动杀掉衍生进程
在执行 shell输入框中加入BUILD_ID=dontKillMe ,即可防止jenkins杀死启动的进程 export BUILD_ID=dontKillMe PROJECT_LOCATION=& ...