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题. 觉得和之前做的某题很像,但翻 ...
随机推荐
- Microsonf visual c++ 14+ 离线内网安装
内网离线安装方法:先下载官方的visualcppbuildtools: <br href=http://go.microsoft.com/fwlink/?LinkId=691126 >& ...
- java 判断数据是否为空
/** * 方法描述:自定义判断是否为空 * 创建作者:李兴武 * 创建日期:2017-06-22 19:50:01 * * @param str the str * @return the bool ...
- 用apscheduler写python定时脚本
apscheduler 官方文档:http://apscheduler.readthedocs.io/en/latest/ 写一个后台定时任务,一般2个选择,一个是apscheduler,一个cele ...
- 搭建第一个scrapy项目的常见问题
错误1:在执行 scrapy crawl spider名命令的时候 出现了ImportError:DLL load failed: %1不是有效的win32程序错误 这是因为pywin32的版本安装错 ...
- Codeforces Global Round 3:B. Born This Way
Born This Way原文链接:[传送门] 题目大意:潇洒哥想乘坐飞机从A地到达C地,但是没有直达的航班,在A地和B地之间有一个可以中转的航班B,潇洒哥想早点到达C地(有航班就坐),但是很不幸他得 ...
- map-apply-applymap
In [1]: import warnings import math import pandas as pd import numpy as np import matplotlib warning ...
- 线索二叉树的详细实现(C++)
线索二叉树概述 二叉树虽然是非线性结构,但二叉树的遍历却为二又树的结点集导出了一个线性序列.希望很快找到某一结点的前驱或后继,但不希望每次都要对二叉树遍历一遍,这就需要把每个结点的前驱和后继信息记录下 ...
- Model&Form&ModelForm拾遗
Model&Form&ModelForm拾遗 一.Model&Form&ModelForm Model:用于用户请求数据的验证(针对性弱),但有强大的数据库操作 For ...
- Qt那点事儿(一)
原文http://www.cnblogs.com/andreitang/archive/2011/08/03/2125815.html 第一回 Signal和Slot是同步的还是异步的? 我们知道Qt ...
- vue 实现上一周、下一周切换功能
效果图: html 显示部分: js 显示部分: preNextBtn(val){ let _this = this; this.tableList = []; //数据重置为空 _this.show ...