Forest Picture

Input Specification

There are more test cases. Each case starts with a line contai

ning two integers

M

,

N

separated

by space (1

M

100, 1

N

10

5

). Next, there are

N

lines, each line contains a triple of

integers

S

,

X

,

Y

, separated by spaces, which describe one standing tree or on

e tree stump. The

values of

X

and

Y

represent the coordinates of the center of either tree roots

or a tree stump.

In case of

S

= 0 the triple describes a stump. In case of

S >

0 the triple describes a standing

tree with height

S

. It holds 0

S

9

,

10

9

X, Y

10

9

.

It is guaranteed that no parts of two different standing trees a

nd/or tree stumps should be

depicted by the same pixel.

Output Specification

For each test case, print the canvas with the image of the glad

e. The top row of the canvas

should be the first printed row of the image. The bottom row of t

he canvas should be the

last printed row of the image. The printout should be decorat

ed by a square border made of

asterisk characters (“

*

”, ASCII code 42), the thickness of the border should be one pi

xel. The

border should frame the canvas tightly, that is, there shoul

d be no spaces between the border

and canvas neither horizontally nor vertically. Print one e

mpty line after each case.

Sample Input

3 2

0 5 5

9 1 0

8 10

3 3 2

0 2 1

1 -1 -1

0 -1 2

3 0 6

6 4 7

0 7 4

3 8 -1

5 5 -5

9 2 -10

Output for Sample Input

*****

*/|\*

*/|\*

*_|_*

*****

**********

*|\._|_..*

*|_.^....*

*../|\...*

*../|\._o*

*../|\...*

*_._|_../*

*._o_.^./*

*\.^./|\/*

**********

AC代码

Select Code

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int mp[120][120], m;
int p(int x, int y)
{
    if(x>=0&&x<m&&y>=0&&y<m)
        return 1;
    return 0;
}
int main()
{
    int  n, i, j, s, x, y, k;
    while(scanf("%d %d",&m, &n)!=EOF)
    {
        memset(mp, 46, sizeof(mp));
        for(i = 0; i<n; i++)
        {
            scanf("%d %d %d",&s, &y, &x);
            if(s==0)
            {
                if(p(x, y))
                    mp[x][y] = 111;
                if(p(x, y-1))
                    mp[x][y-1] = 95;
                if(p(x, y+1))
                    mp[x][y+1] = 95;
            }
            if(s!=0)
            {
                if(p(x, y))
                    mp[x][y] = 124;
                if(p(x, y-1))
                    mp[x][y-1] = 95;
                if(p(x,y+1))
                    mp[x][y+1] = 95;
                for(k = 1; k<=s; k++)
                {
                    if(p(x+k,y))
                    {
                        mp[x+k][y] = 124;
                    }
                    if(p(x+k,y-1))
                    {
                        mp[x+k][y-1] = 47;
                    }
                    if(p(x+k, y+1))
                    {
                        mp[x+k][y+1] = 92;
                    }
                }
                if(p(x+s+1,y))
                {
                    mp[x+s+1][y] = 94;
                }
            }
        }
        for(i = 0; i<m+2; i++)
            printf("*");
        printf("\n");
        for(i = m-1; i>=0; i--)
        {
            printf("*");
            for(j = 0; j<m; j++)
            {
                printf("%c",mp[i][j]);
            }
            printf("*\n");
        }
        for(i = 0; i<m+2; i++)
            printf("*");
        printf("\n");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41524782/article/details/82495786