zoukankan      html  css  js  c++  java
  • 【CF1028A】Find Square(签到)

    题意:给定矩阵里,找到由B构成的矩形的中心

    n,m<=115

    思路:

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<string>
     4 #include<cmath>
     5 #include<iostream>
     6 #include<algorithm>
     7 #include<map>
     8 #include<set>
     9 #include<queue>
    10 #include<vector>
    11 using namespace std;
    12 typedef long long ll;
    13 typedef unsigned int uint;
    14 typedef unsigned long long ull;
    15 typedef pair<int,int> PII;
    16 typedef vector<int> VI;
    17 #define fi first
    18 #define se second 
    19 #define MP make_pair
    20 #define N   2100000 
    21 #define MOD 1000000007
    22 #define eps 1e-8 
    23 #define pi acos(-1)
    24 
    25 int a[200][200];
    26 char s[200];
    27 
    28 int read()
    29 { 
    30    int v=0,f=1;
    31    char c=getchar();
    32    while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
    33    while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
    34    return v*f;
    35 }
    36 
    37 void swap(int &x,int &y)
    38 {
    39     int t=x;x=y;y=t;
    40 }
    41 
    42 
    43 int main()
    44 {
    45   
    46     int n,m; 
    47     scanf("%d%d",&n,&m); 
    48     for(int i=1;i<=n;i++)
    49     {
    50         scanf("%s",s);
    51         for(int j=0;j<=m-1;j++) 
    52          if(s[j]=='B') a[i][j+1]=1;
    53     }
    54     int ansx=0;
    55     int ansy=0;
    56     for(int i=1;i<=n;i++)
    57      for(int j=1;j<=m;j++)
    58       if(a[i][j]==1&&ansx+ansy==0)
    59       {
    60           int x,y;
    61           x=i; y=j;
    62           while(x<=n&&a[x][j]==1) x++;
    63         x--;
    64         while(y<=m&&a[i][y]==1) y++;
    65         y--;
    66         ansx=(i+x)/2;
    67         ansy=(j+y)/2;
    68 
    69       }
    70     printf("%d %d
    ",ansx,ansy);
    71 }
  • 相关阅读:
    this指向问题
    原生js实现的金山打字小游戏(实例代码详解)
    js实现点赞效果
    .net core部署到linux可能碰到的问题
    Linux curl命令详解 Web程序
    用十年来学编程
    JAVA的字符串拼接与性能
    PHP学习的技巧和学习的要素总结
    php实现验证邮箱格式的代码实例
    PHP页面中文乱码处理办法
  • 原文地址:https://www.cnblogs.com/myx12345/p/9844152.html
Copyright © 2011-2022 走看看