码迷,mamicode.com
首页 > 其他好文 > 详细

CF 965 B. Battleship

时间:2018-04-30 15:31:03      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:def   led   port   print   pos   test   oca   单元   str   

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.

读了好几遍终于看懂了题目意思,"#"代表空单元,"."代表船部件,并且水平或者竖直的连起来的k个可能构成一个完整的部件,问有没有一个单元可以和其他单元组合构成尽可能多的部件,暴力一下。

#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;
int main()
{
    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;
}

 

CF 965 B. Battleship

标签:def   led   port   print   pos   test   oca   单元   str   

原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/8973578.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!