zoukankan      html  css  js  c++  java
  • Codeforces AIM Tech Round 5 (rated, Div. 1 + Div. 2)

    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 (1n,m1151≤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 si1si2simsi1si2…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 (1rn1≤r≤n, 1cm1≤c≤m) separated by a space — the row and column numbers of the center of the black square.

    Examples
    input
    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
    ", 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
    ", r + 1, c + 1);
    	}
    	return 0;
    }
    

      

      

  • 相关阅读:
    HTML5侧滑聊天面板
    HTML5世界地图
    BZOJ_1042_[HAOI2008]硬币购物_容斥原理+背包
    BZOJ_1342_[Baltic2007]Sound静音问题_单调队列
    BZOJ_2343_[Usaco2011 Open]修剪草坪 _单调队列_DP
    BZOJ_2595_[Wc2008]游览计划_斯坦纳树
    BZOJ_5180_[Baltic2016]Cities_ 斯坦纳树
    BZOJ_4006_[JLOI2015]管道连接_斯坦纳树
    51nod_1412_AVL树的种类_动态规划
    BZOJ_3143_[Hnoi2013]游走_期望DP+高斯消元
  • 原文地址:https://www.cnblogs.com/darkchii/p/9598829.html
Copyright © 2011-2022 走看看