CF 965 B. Battleship

Arkady is playing Battleship. The rules of this game aren't really important.There is a field of n×n

cells. There should be exactly one k-decker on the field, i. e. a ship that is kcells long oriented either horizontally or vertically. However,

Arkady doesn't know where it is located. For each cell Arkady knows if it is definitely empty or can contain a part of the ship.

Consider all possible locations of the ship. Find such a cell that belongs to the maximum possible number of different locations of the ship.

Input

The first line contains two integers n and k (1kn100) — the size of the field and the size of the ship.

The next n lines contain the filed.Each line cotains ncharacters, each of which is either '#' (denotes a definitely empty cell) or '.' (denotes a cell that can belong to the ship).

Output

Output two integers — the row and the column of a cell that belongs to the maximum possible number of different locations of the ship.

If there are multiple answers, output any of them. In particular, if no ship can be placed on the field, you can output any cell.

Examples
Input
4 3
#..#
#.#.
....
.###
Output
3 2
Input
10 4
#....##...
.#...#....
..#..#..#.
...#.#....
.#..##.#..
.....#...#
...#.##...
.#...#.#..
.....#..#.
...#.#...#
Output
6 1
Input
19 6
##..............###
#......#####.....##
.....#########.....
....###########....
...#############...
..###############..
.#################.
.#################.
.#################.
.#################.
#####....##....####
####............###
####............###
#####...####...####
.#####..####..#####
...###........###..
....###########....
.........##........
#.................#
Output
1 8
Note

The picture below shows the three possible locations of the ship that contain the cell (3,2)

in the first sample.

After reading it several times, I finally understood the meaning of the title, "#" represents an empty unit, "." represents a ship part, and k connected horizontally or vertically may form a complete part, ask if there is a unit that can be combined with Combining other units to form as many parts as possible, brute force.

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
#define mem(a) ((a,0,sizeof(a)))
typedef long long ll;
char a[106][106];
int vis[106][106];
int n,k;
intmain()
{
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%s",&a[i]);
    int col=0,row=0,cnt=0,tot=0;
    memset(vis,0,sizeof(vis));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(a[i][j]=='.')
            {
                cnt=0;
                for(int z=j;z<min(n,j+k);z++)
                    if(a[i][z]=='.') cnt++;
                if(cnt==k){
                    for(int z=j;z<min(n,j+k);z++)
                        vis [i] [z] ++ ;
                }
                cnt=0;
                for(int z=i;z<min(n,i+k);z++)
                    if(a[z][j]=='.') cnt++;
                if(cnt==k){
                    for(int z=i;z<min(n,i+k);z++)
                        vis [z] [j] ++ ;
                }
            }
            if(vis[i][j]>tot)
            {
                tot = vis [i] [j];
                row=i;
                col = j;
            }
        }
    }
    printf("%d %d\n",row+1,col+1);
    return 0;
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325073798&siteId=291194637
Recommended