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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Light2Chasers/article/details/82127153
  1. problem link:嗯哼~在这里

  2. 题意:在一个n*m的白色矩阵中,有一个边长大小为奇数的正方形。请求出它最中间那个位置的坐标。

  3. 解题思路:这题。。。我也是醉了,刚点进去电脑就开始卡,,,卡到已经有98个人做出来了,我连题目都看不到。喏,就是先找到第一个‘B’的坐标,然后计算这个正方形的边长大小。然后找下坐标规律就出来了。

  4. AC code:

#include<iostream>
using namespace std;
string s[118]; 
int n,m,len,x,y;
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n>>m;int flag=1;
    for(int i=1;i<=n;i++)cin>>s[i];
    for(int i=1;i<=n;i++){
        for(int j=0;j<m;j++){
            if(flag&&s[i][j]=='B'){flag=0;x=i,y=j+1,len++;break;}
        }
        if(!flag)break;
    }
    for(int i=y;i<m;i++)if(s[x][i]=='B')len++;else break;
    cout<<x+len/2<<" "<<y+len/2<<endl;
}

猜你喜欢

转载自blog.csdn.net/Light2Chasers/article/details/82127153