codeforces 384A Coder

点击打开链接

A. Coder
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y)(x–1, y)(x, y + 1)and (x, y–1).

Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.

Input

The first line contains an integer n (1 ≤ n ≤ 1000).

Output

On the first line print an integer, the maximum number of Coders that can be placed on the chessboard.

On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'.

If there are multiple correct answers, you can print any.

Examples
input
2
output
2
C.
.C

模拟

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d", &n);
    char s[1100][1100];
    memset(s, '.', sizeof(s));
    int sum = 0;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            bool flag = true;
            int p = i - 1, q = i + 1;
            if(p >= 1 && p <= n && s[p][j] == 'C')
            {
                flag = false;
            }
            if(q >= 1 && q <= n && s[q][j] == 'C')
            {
                flag = false;
            }
            p = j - 1;
            q = j + 1;
            if(p >= 1 && p <= n && s[i][p] == 'C')
            {
                flag = false;
            }
            if(p >= 1 && p <= n && s[i][q] == 'C')
            {
                flag = false;
            }
            if(flag)
            {
                s[i][j] = 'C';
                sum++;
            }
        }
    }
    printf("%d\n", sum);
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            printf("%c", s[i][j]);
        }
        printf("\n");
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值