zoukankan      html  css  js  c++  java
  • CodeForces

    Hongcow likes solving puzzles.

    One day, Hongcow finds two identical puzzle pieces, with the instructions “make a rectangle” next to them. The pieces can be described by an n by m grid of characters, where the character ‘X’ denotes a part of the puzzle and ‘.’ denotes an empty part of the grid. It is guaranteed that the puzzle pieces are one 4-connected piece. See the input format and samples for the exact details on how a jigsaw piece will be specified.

    The puzzle pieces are very heavy, so Hongcow cannot rotate or flip the puzzle pieces. However, he is allowed to move them in any directions. The puzzle pieces also cannot overlap.

    You are given as input the description of one of the pieces. Determine if it is possible to make a rectangle from two identical copies of the given input. The rectangle should be solid, i.e. there should be no empty holes inside it or on its border. Keep in mind that Hongcow is not allowed to flip or rotate pieces and they cannot overlap, i.e. no two ‘X’ from different pieces can share the same position.

    Input
    The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece.

    The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters ‘.’ and ‘X’ only. ‘X’ corresponds to a part of the puzzle piece, ‘.’ is an empty space.

    It is guaranteed there is at least one ‘X’ character in the input and that the ‘X’ characters form a 4-connected region.

    Output
    Output “YES” if it is possible for Hongcow to make a rectangle. Output “NO” otherwise.

    Example
    Input
    2 3
    XXX
    XXX
    Output
    YES
    Input
    2 2
    .X
    XX
    Output
    NO
    Input
    5 5
    …..
    ..X..
    …..
    …..
    …..
    Output
    YES
    Note
    For the first sample, one example of a rectangle we can form is as follows

    111222
    111222
    For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.

    In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle:

    …..
    ..XX.
    …..
    …..
    …..

    判断两块相同的有X的区域是否能拼成一个矩形,也就是说,矩形才能拼成矩形,判断X是否是一个矩形即可

    #include<stdio.h>///判断是否是X字符组成一个矩形即可
    #include<string.h>
    int main()
    {
        int n,m,i,j;
        char a[508][509];
        while(scanf("%d%d",&n,&m)!=EOF)
        {
            int flag=0,minx=600,miny=600,maxx=-1,maxy=-1;
            for(i=1;i<=n;i++)
            {
                scanf("%s",a[i]+1);
                for(j=1;j<=m;j++)
                {
                    if(a[i][j]=='X')
                    {
                        flag++;
                        if(i<minx)minx=i;
                        if(i>maxx)maxx=i;
                        if(j<miny)miny=j;
                        if(j>maxy)maxy=j;
                    }
                }
            }
            int sum=(maxx-minx+1)*(maxy-miny+1);
            if(sum==flag)printf("YES
    ");
            else printf("NO
    ");
        }
    }
    
  • 相关阅读:
    python下RSA 加密/解密,签名/验证
    python字符串str和字节数组相互转化
    代码存档
    windows 7 安装 scrapy
    scrapy 爬取自己的博客
    win32api 找不到指定的模块
    SQLite3日期与时间,常见函数
    sqlite3日期数据类型
    myeclipse集成maven
    UIKit class hierarchy
  • 原文地址:https://www.cnblogs.com/kuronekonano/p/11794339.html
Copyright © 2011-2022 走看看