2018六校联赛-五月月赛 ---三角形or四边形?

1999: 三角形or四边形?

描述

题目描述:

JiangYu很无聊,所以他拿钉子在板子上戳出了一个由.#组成的10*10八联通点阵图。请机智的你判断图中的#组成的是三角形还是四边形?

其中一种3 jiao *为

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . # . . . . .

. . . # . # . . . .

. . # . . . # . . .

. # . . . . . # . .

######### .

. . . . . . . . . .

. . . . . . . . . .

其中一种4 bian *为

. . . . . . . . . .

. . . . . . . . . .

. ########.

. # . . . . . . #.

. # . . . . . . #.

. # . . . . . . #.

. ########.

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

输入:

一个10*10点阵图

输出:

三角形输出"3 jiao *“四边形输出"4 bian *”

样例输入
..........
..........
..........
....#.....
...#.#....
..#...#...
.#.....#..
#########.
..........
..........
样例输出
3 jiao *

提示

保证每条边长度>2,保证所有的#之间是联通的。


题目很简单,然而我还是一下午都没做出来,代码能力太弱了。题目只有10 * 10,所以可以直接暴力做,而且不用考虑其他情况,要么三角形,要么四边形。所以对于每一个‘#’点,判断是否为顶点即可,而且‘#’点不为顶点的情况只有4种(横,竖,左斜,右斜),除此以外就是顶点。


#include <bits/stdc++.h>
using namespace std;

const int maxn = 15;
char maze[maxn][maxn];
int cont = 0;

int is_node(int x,int y)
{
    if(x == 1 || x == 10)
    {
        if(y == 1 || y == 10)
        {
            return 1;
        }
        if(maze[x][y - 1] == '#' && maze[x][y + 1] == '#')
        {
            return 0;
        }
        else
        {
            return 1;
        }
    }
    if(y == 1 || y == 10)
    {
        if(x == 1 || x == 10)
        {
            return 1;
        }
        if(maze[x - 1][y] == '#' && maze[x + 1][y] == '#')
        {
            return 0;
        }
        else
        {
            return 1;
        }
    }
    if((maze[x - 1][y] == '#' && maze[x + 1][y] == '#') || (maze[x][y + 1] == '#' && maze[x][y - 1] == '#'))
    {
        return 0;
    }
    if((maze[x - 1][y - 1] == '#' && maze[x + 1][y + 1] == '#') || (maze[x - 1][y + 1] == '#' && maze[x + 1][y - 1] == '#'))
    {
        return 0;
    }
    return 1;
}

int main()
{
    for(int i = 1;i <= 10;i++)
    {
        scanf("%s",maze[i] + 1);
    }
    for(int i = 1;i <= 10;i++)
    {
        for(int j = 1;j <= 10;j++)
        {
            if(maze[i][j] == '#')
            {
                if(!cont)
                {
                    cont++;
                }
                else
                {
                    if(is_node(i,j))
                    {
                        cont++;
                    }
                }
            }
        }
    }
    if(cont == 3)
    {
        printf("3 jiao *\n");
    }
    if(cont == 4)
    {
        printf("4 bian *\n");
    }
    return 0;
}



猜你喜欢

转载自blog.csdn.net/eric_chen_song_lin/article/details/80295659