codeforce1028A Find Square

link:http://codeforces.com/problemset/problem/1028/A

让找出字符串矩阵中B的中心

模拟即可,以下思路值得学习

#include<bits/stdc++.h>
using namespace std;
int X,Y,n,m,cnt;char s[1005];
int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++)
    {
        scanf("%s",s+1);
        for (int j=1;j<=m;j++)
            if (s[j]=='B') cnt++,X+=i,Y+=j;
    }
    
    X/=cnt;Y/=cnt;
    printf("%d %d\n",X,Y);
    return 0;
}

 

posted @ 2018-08-31 01:26  Somnus、M  阅读(122)  评论(0编辑  收藏  举报