Problem B. Black and White Gym-100801B] 想象力

来源:互联网 发布:mac重装没有磁盘 编辑:程序博客网 时间:2024/06/05 03:19

Problem B. Black and White

原题文档:https://odzkskevi.qnssl.com/f8fd72d9900eebaf15d7ea41975a6532?v=1501122426
Input le:
black.in
Output le:
black.out
Time limit:
2 seconds
Memory limit:
256 megabytes
The jury has a great artistic idea | to create a rectangular panel out of a huge pile of black and white
squares of the same size. The panel should have exactly
b
4-connected areas made of black tiles, and
w
4-connected areas made of white tiles.
Remember, a
4-connected area
of some color is a maximal set of the panel tiles such that:

any two tiles of the area share the same color;

for any two tiles of the area there is a tile sequence connecting them, such that any two consecutive
tiles of the sequence share a common side.
In addition to the artistic idea, the jury has already developed a program that produces design of the
panel. But since this problem is about art, any new solution is extremely important for the jury.
Input
The only line of the input le contains two integers
b
and
w
| number of black and white areas
(1

b; w

1000).
Output
The rst line of the output le should contain the picture sizes
r
and
c
| the number of rows and columns
(1

r; c

100 000). This line should be followed by
r
lines of
c
symbols each. Each symbol should be
either
@
' (for black tile) or

.
’ (for white one). There should be no more than 100 000 tiles in the panel.
Example

black.in
2 3

black.out
6 7
@@@@@@@
@.@@@@@
@@…@@
@@@@@@@
…….
@@@@@@@

这个。。。考验的是想象力?

1.上边五百行 下边五百行 跳着填充

#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>using namespace std;const int maxn = 1e3+5;char s[maxn][105];int main(){    int i, j;//    freopen("black.in","r",stdin);//    freopen("black.out","w",stdout);    int b, w;    while(cin>>b>>w)    {        --b;--w;        for(i = 0; i < 500;i++)        {            for(j = 0; j<100;j++)                s[i][j] = '@';        }        for(i = 500; i<1000;i++)        {            for(j=0;j<100;j++)                s[i][j] = '.';        }        for(i=0;i<500&&w;i+=2)        {            for(j=0;j<100&&w;j+=2)            {                --w;s[i][j] = '.';            }        }        for(i=501;i<1000&&b;i+=2)        {            for(j=0;j<100&&b;j+=2)            {                --b;s[i][j]='@';            }        }        printf("1000 100\n");        for(i=0;i<1000;i++)        {            for(j=0;j<100;j++)                printf("%c",s[i][j]);            printf("\n");        }        puts("");    }    return 0;}

2.

#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;int main(){    int n,m;    char c[2] = {'.','@'};    //freopen("black.in","r",stdin);    //freopen("black.out","w",stdout);    scanf("%d%d",&n,&m);    if(n > m)    {        std::swap(n,m);        std::swap(c[0],c[1]);    }    printf("%d %d\n",2*m,3);    for(int i = 0;i < (m-n);i ++)//用多的把少的圈起来    {        printf("%c%c%c\n%c%c%c\n",c[1],c[1],c[1],c[1],c[0],c[1]);    }    for(int i = 0;i < n;i ++)//当黑白要求一样时不断间隔输出,各一行!    {        printf("%c%c%c\n%c%c%c\n",c[1],c[1],c[1],c[0],c[0],c[0]);    }    return 0;}
原创粉丝点击