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
Copy
5 6 WWBBBW WWBBBW WWBBBW WWWWWW WWWWWW
output
Copy
2 4
input
Copy
3 3 WWW BWW WWW
output
Copy
2 1
题意:给n行m列WB字符,找出最中间的B的位置。
题解:规律.... 不是看别人代码还真内看出来....所有B横纵坐标各自之和除以B的总个数。
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,sum=0,r=0,col=0;
char c;
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
cin>>c;
if (c=='B') r+=i,col+=j,sum++;
}
cout<<r/sum<<" "<<col/sum<<endl;
return 0;
}