Putting Plates 摆盘

Putting Plates 摆盘

来源codeforses #1530B
1200
链接: [link](链接: link.
time limit per test: 2 seconds
每次测试的时间限制:2秒

memory limit per test: 512 megabytes
每次测试的内存限制:512兆字节

input: standard input
输入:标准输入

output: standard output
产出:标准产出

To celebrate your birthday you have prepared a festive tablel Now you want to seat as many guests as possible.
为了庆祝你的生日,你已经准备了一个节日餐桌,现在你想要座位尽可能多的客人。

The table can be represented as a rectangle with height h and with u, divided into h x u clls.Let (i,j) denote the cellin the i-th ow and
表可以表示为高度h和u的矩形,分为hx u cll,设(i,j)表示i-th中的单元格,

the j-th column of the rectangle (1 <i<h;1<j <w).
矩形的j列(1<i<h;1<j<w).

lnto each cell of the table you can either put a plate or keep it empty.
在桌子的每个细胞里,你要么放一个盘子,要么把它空着。

As each guest has to be seated next to their plate, you can only putplates on the edge of the table— into the firstor the last row of the
因为每位客人都必须坐在他们的盘子旁边,所以你只能把盘子放在桌子的边缘–放在桌子的第一排或最后一行。

rectangle, or into the first or the last column.Formally,for each cell (i,j) you put a plate into, at least one of the following conditions must be
对于每个单元格(i,j),至少要有以下条件之一:

satisfied:i— 1,i—h,j=1,j= w.
满意:i-1,i-h,j=1,j=w.

To make the guests comfortable, no two plates must be put into cells that have a common side or comer.Iin other words fcell(i,j) contains a
为了让客人感到舒服,不要把两个盘子放进有共同侧面或角落的牢房里。换句话说,FCell(I,j)包含一个

plate, you can’t put plates into cells(i—1,j).(i,j一1).(i++1,j).(i,j+1).(i—1,j-1).(i—1,j+1).(i+1,j-1).
(i+1,j).(i+1,j).(i,j+1).(i-1,j-1).(i-1,j+1).(i+1,j-1).(i+1,j-1)。

(+1,j+1).
(+1,j+1).

Put as many plates on the table as possible without violating the rules above.
把尽可能多的盘子放在桌子上,而不违反上面的规则。

lnput
输入

The first line contains a single integert (1 <t <100)—the number of test cases.
第一行包含一个整数(1<t<100)–测试用例的数量。

Each of the following t lines describes one test case and contains two integers h and u(3<h,u<20)—the height and the width of the
下面的t行描述一个测试用例,并包含两个整数h和u(3<h,u<20)–高度和宽度

table.
桌子。

Output
输出量

For each test case,print h lines containing u characters each.Character jin line i must be equal to 1 if you are putng a plale itocll(,j)
对于每个测试用例,都要打印包含u个字符的h行,如果要输入Plale itocll(,j),则字符jin行i必须等于1。

and 0 otherwise.
否则就0。

All plates must be put on the edge of the table.No two plates can be put into cells that have a common side or comer.The umber of plates
所有的盘子都必须放在桌子的边缘上。没有两个盘子可以放在有共同侧面或凹凸的细胞里。

put on the table under these conditions must be as large as possible.
在这些条件下摆在桌面上的人必须尽可能大。

You are allowed to print additional empty lines.
允许打印其他空行。

构造

int main()
{
    int n;

    cin >> n;
    while (n--)
    {
        bool map[21][21] = { 0 };
        int h, w;
        cin >> h >> w;

        map[0][0] = 1;//1
        map[0][w - 1] = 1;
        map[h - 1][0] = 1;
        map[h - 1][w - 1] = 1;
        for (int i = 2; i < w-1; ++i)//1-
        {
            if (!map[0][i - 1]&& !map[0][i+1])
                map[0][i] = 1;
        }

        for (int i = 2; i < h-1; ++i)//2|
        {
            if (!map[i - 1][0]&&!map[i+1][0])
                map[i][0] = 1;
        }

        for (int i = 2; i < w-1; ++i)//3- -
        {
            if (!map[h - 1][i - 1] && !map[h - 2][i - 1]&& !map[h - 1][i +1] && !map[h - 2][i +1])
                map[h - 1][i] = 1;
        }


        for (int i = 1; i < h-1; ++i)//4| |
        {
            if (!map[i - 1][w - 1] && !map[i - 1][w - 2]&&!map[i+1][w -1]&&!map[i+1][w-2])
                map[i][w - 1] = 1;
        }

        for (int i = 0; i < h; ++i)
        {
            for (int j = 0; j < w; ++j)
            {
                cout << map[i][j];
            }
            cout << endl;
        }
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值