zoukankan      html  css  js  c++  java
  • 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.

    读了好几遍终于看懂了题目意思,"#"代表空单元,"."代表船部件,并且水平或者竖直的连起来的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
    ",row+1,col+1);
        return 0;
    }
  • 相关阅读:
    Android中fragment之间和Activity的传值、切换
    javascript--经典实例锦集
    Android中ListView动态加载数据
    Android开发之调用系统图库及相机
    Android 相机开发详解
    RTSP实例解析
    【Android UI设计与开发】第18期:滑动菜单栏(三)SlidingMenu动画效果的实现
    js 第二小步
    JavaScript初步+基本函数
    javaweb实战开始
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/8973578.html
Copyright © 2011-2022 走看看