Berland Flag

Berland Flag
Time limit per test: 0.5 second(s)
Memory limit: 65536 kilobytes
input: standard
output: standard

The Berland is in trouble again. After the recent elections All-Berland Great Duma has divided into two coalitions: Blue-eyed coalition and Red-eyed coalition. On the independence day the following question was raised: what will the national flag look like? Both coalitions agreed that the flag should be a square of N2 x N2 cells, each of them painted blue of red. To make the flag acceptable for both coalitions, the following requirements must be held:
  • every row of the flag must contain exactly K blue cells
  • every column of the flag must contain exactly K blue cells
  • if we split the flag into squares of N x N cells (there will be N x N such squares), then every such square must contain exactly K blue cells. You are the chief programmers in Berland. So, making the flag model is your duty.
    Input
    First line of the input contains two integer numbers N and K (1 ≤ N ≤ 20, 0 ≤ KN2).
    Output
    Output description of the desired flag. Print N2 lines which consist of N2 characters
    '*'
    and
    '.'
    , where
    '*'
    means blue cell and
    '.'
    means red cell. Output
    "NO SOLUTION"
    (without quotes), if there is no flag which satisfies both coalitions. If there are several solutions, output any of them.
    Example(s)
    sample input
    sample output
    2 2
    
    *..*
    .**.
    .**.
    *..*
    

    sample input
    sample output
    3 1
    
    *........
    ...*.....
    ......*..
    .*.......
    ....*....
    .......*.
    ..*......
    .....*...
    ........*
    




    样例很重要,这道题有爱之处就在于,第二个样例就把一个很简单的规律展现出来了。


  • #include <cstdlib> 
    #include <iostream> 
    #include <cstring> 
    #include <cstdio> 
    #include <algorithm> 
    #include <cmath> 
    using namespace std;   
    char mp[500][500]; 
    int n, K;   
    void build(int ii, int jj)
    {     
        const int PX= (jj-1)*n;
        const int PY= (ii-1)*n;     
        int x= ii, y= jj;     
        int cnt= 0;     
        for(int k=0;k<K;k++)
        {         
            mp[PX+x][PY+y]= '*';         
            y++;         
            if (y>n)    
             y= 1;         
            if (y==jj)
            {             
                x++;             
                if (x>n)    
                 x= 1;         
            }     
        }   
    }   
    int main()
    {     
        while(~scanf("%d%d", &n, &K))
        {         
            for(int i=1;i<=n*n;i++) 
            for(int j=1;j<=n*n;j++) 
             mp[i][j]= '.';         
            for(int i=1;i<=n;i++)             
             for(int j=1;j<=n;j++)                 
              build(i, j);         
            for(int j= 1;j<=n*n;j++)
            {             
                for(int i=1;i<=n*n;i++)                 
                 printf("%c", mp[i][j]);             
                printf("\n");         
            }     
        }   
    }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值