Hrbust 2313 Circle Fan【模拟+思维】

75 篇文章 0 订阅

Circle Fan
Time Limit: 1000 MSMemory Limit: 131072 K
Total Submit: 9(2 users)Total Accepted: 3(2 users)Rating: Special Judge: No
Description

Alex loves circles. No particular reason, just love them. So he comes up with a problem with circles.

There are some circles on an N*M table. The top-left corner of the table is considered as coordinate (1, 1) and the bottom-right corner is (N, M). A circle on the table is defined by the following rules:

Let's say the center of a circle is at (x, y) and the radius of the circle is r. Then all the points whose coordinate (i, j) satisfies (x - i)^2+(y - j)^2 <= r*r form this circle. So you can see a circle contains several rows and columns. The left-most and the right-most point of all the rows the circle contains and the top-most and the bottom-most point of all the columns the circle contains, all these points form the outline of the circle. All the other points the circle contains are considered to be inside the circle.

...X...

.XXOXX.

.XOOOX.

XOOOOOX

.XOOOX.

.XXOXX.

...X...

The figure above is an example. This is a circle of radius 3. All the 'X' points form the outline of the circle and 'O' points are inside the circle.

Now here comes the problem. Given the center coordinate and the radius of severe circles on the table, can you show us how the table looks like by drawing it? For each circle, you only need to draw its outline (all the 'X' points). For every point of the table, if it is on the outline of a circle, draw 'X', otherwise '.'. There may be many circles on the table, so some circles may overlap others. If a circle A is partly covered by circle B, then all the points which are on the outline of A and inside circle B cannot be seen (use '.' instead of 'X') and if A is covered by B entirely, then don't draw A at all. Some parts of the outlines may be out of the table, you don't need to draw those parts. If you don't understand these rules, take a look at the sample output.

Input

Multiple test cases. The first line contains a positive integer T (T<=10) indicates the number of test cases.

For each case, the first line contains three numbers: n, m, k (1<=n, m<=100, k<=10), meaning the table has n rows and m columns and there are k circles.

The next k lines contain k circles. Each line contains three numbers: xi, yi, ri (1<=xi<=n, 1<=yi<=m, 1<=ri<=100), meaning the ith circle has center (xi, yi) and radius ri. For every circle i, j (1<=i<j<=k), when circle i and circle j have intersect part, circle i covers circle j.

Output

First print the case number in a single line. Then draw the table following the rules mentioned above.

Print a blank line after each case.

Sample Input

1

30 30 3

13 13 7

10 10 9

25 28 10

Sample Output

Case 1:

.........X....................

.....XXXX.XXXX................

....X.........X...............

...X...........X..............

..X.............X.............

.X..........X....X............

.X.......XXX.XXX.X............

.X......X.......XX............

.X.....X.........X............

X.....X...........X...........

.X....X...........X...........

.X....X...........X...........

.X...X.............X..........

.X....X...........X...........

..X...X...........X........X..

...X..X...........X....XXXX.XX

....X..X.........X...XX.......

.....XXXX.......X...X.........

.........XXX.XXX...X..........

............X......X..........

..................X...........

..................X...........

..................X...........

..................X...........

.................X............

..................X...........

..................X...........

..................X...........

..................X...........

...................X..........

Source
"尚学堂杯"哈尔滨理工大学第六届程序设计竞赛

题目大意:

一个N*M大小的一个图,初始的时候上边都是“”.“”,接下来我们有k个圆,我们每一次放在图上一个圆的时候,如果其原本整个圆的位子上已经有了圆,那么对应我们这个圆就忽略掉,我们每一次放上一个圆之后我们都要将其轮廓描出来。

我们要得到最终的图。


思路:


1、因为K不大,所以我们直接暴力将圆覆盖到图上,然后描出轮廓即可,因为覆盖相关问题,之后的小圆会被之前的大圆覆盖掉,那么我们考虑逆序处理即可。


2、边界问题需要注意(分享自队长的数据):

1

10 10 1
5 5 6


Ac代码:

#include<stdio.h>
#include<string.h>
using namespace std;
char ans[1000][1000];
struct node
{
    int x,y,r;
} p[155];
int fx[4]={0,0,1,-1};
int fy[4]={1,-1,0,0};
int n,m,k;
void Slove(int contx,int conty,int contr)
{
    for(int i=1;i<=500;i++)
    {
        for(int j=1;j<=500;j++)
        {
            if(ans[i][j]=='o')
            {
                for(int z=0;z<4;z++)
                {
                    int xx=i+fx[z];
                    int yy=j+fy[z];
                    if(ans[xx][yy]!='o'&&ans[xx][yy]!='*')ans[i][j]='*';
                }
            }
        }
    }
    for(int i=1;i<=500;i++)
    {
        for(int j=1;j<=500;j++)
        {
            if(ans[i][j]=='o')
            {
                ans[i][j]='.';
            }
            if(ans[i][j]=='*')
            {
                ans[i][j]='X';
            }
        }
    }
}
int main()
{
    int t;
    int kase=0;
    scanf("%d",&t);
    while(t--)
    {
        memset(ans,'.',sizeof(ans));
        scanf("%d%d%d",&n,&m,&k);
        int tmpn=500;int tmpm=500;
        for(int i=0; i<k; i++)
        {
            scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].r);
            p[i].x+=200;
            p[i].y+=200;
        }
        for(int z=k-1;z>=0;z--)
        {
            for(int i=1; i<=500; i++)
            {
                for(int j=0; j<=500; j++)
                {
                    if((i-p[z].x)*(i-p[z].x)+(j-p[z].y)*(j-p[z].y)<=p[z].r*p[z].r)
                    {
                        ans[i][j]='o';
                    }
                }
            }
            Slove(p[z].x,p[z].y,p[z].r);
        }
        printf("Case %d:\n",++kase);
        for(int i=201;i<=n+200;i++)
        {
            for(int j=201;j<=m+200;j++)
            {
                printf("%c",ans[i][j]);
            }
            printf("\n");
        }
        printf("\n");
    }
}
/*
10
30 35 8
13 13 6
13 14 7
13 15 5
13 16 5
13 17 5
13 18 5
17 13 4
25 25 10

30 30 2
13 13 7
13 13 6
30 30 2
13 13 7
13 14 6
*/







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值