Codeforces Round #225 (Div. 2)A:Coder 解题报告

来源:互联网 发布:网络特性怎么做营销 编辑:程序博客网 时间:2024/06/06 03:06

题目地址:http://codeforces.com/contest/384/problem/A

大意:在一个n*n的棋盘上现在要在上面尽量多的放棋子,问满足不存在任意两个棋子相邻,最多能放多少个,并模拟出一种情况来。

思路:首先,最多的棋子数,要分别考虑n的奇偶性,通过画出前几个图形,可知道:n是奇数:能放n*n/2 ,n是偶数:能放(n*n+1)/2

        至于模拟,我是用一种取巧的方法遍历得到的,具体的看代码·······

代码:

#include <iostream>using namespace std;int main(){    int n,m,l,p;    cin>>n;    if(n%2==1)        cout<<(n*n+1)/2;    else        cout<<n*n/2;    cout<<endl;    for(int i=1;i<=n;i++)    {        for(int j=1;j<=n;j++)            if(i%2==j%2)cout<<"C";   //主要是这里,不懂的话就画下图···        else cout<<".";        cout<<endl;    }    //cout << "Hello world!" << endl;    return 0;}

0 0
原创粉丝点击