zoukankan      html  css  js  c++  java
  • CodeForces 1221B Knights(思维)

    题目链接:https://vjudge.net/problem/CodeForces-1221B

      可以行列间隔开选一个蓝色棋子,然后让他四个角可以放红色棋子的地方放上红色棋子,最后剩下的地方全都填上蓝色棋子

    #include<set>
    #include<map>
    #include<list>
    #include<stack>
    #include<queue>
    #include<cmath>
    #include<cstdio>
    #include<cctype>
    #include<string>
    #include<vector>
    #include<climits>
    #include<cstring>
    #include<cstdlib>
    #include<iostream>
    #include<algorithm>
    #define endl '\n'
    #define rtl rt<<1
    #define rtr rt<<1|1
    #define lson rt<<1, l, mid
    #define rson rt<<1|1, mid+1, r
    #define maxx(a, b) (a > b ? a : b)
    #define minn(a, b) (a < b ? a : b)
    #define zero(a) memset(a, 0, sizeof(a))
    #define INF(a) memset(a, 0x3f, sizeof(a))
    #define IOS ios::sync_with_stdio(false)
    #define _test printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n")
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> P;
    typedef pair<ll, ll> P2;
    const double pi = acos(-1.0);
    const double eps = 1e-7;
    const ll MOD =  1000000007LL;
    const int INF = 0x3f3f3f3f;
    const double EULC = 0.5772156649015328;
    const int NIL = -1;
    template<typename T> void read(T &x){
        x = 0;char ch = getchar();ll f = 1;
        while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
        while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
    }
    const int maxn = 1e2+10;
    char mp[maxn][maxn];
    void solve(int x, int y, int n) {
        mp[x][y] = 'W';
        if (x-2>=0 && y+1<n) 
        mp[x-2][y+1] = 'B';
        if (x-1>=0 && y+2<n) 
        mp[x-1][y+2] = 'B';
        if (x+2<n && y+1<n) 
        mp[x+2][y+1] = 'B';
        if (x+1<n && y+2<n)
        mp[x+1][y+2] = 'B';
        if (x+2<n && y-1>=0) 
        mp[x+2][y-1] = 'B';
        if (x+1<n && y-2>=0) 
        mp[x+1][y-2] = 'B';
        if (x-2>=0 && y-1>=0) 
        mp[x-2][y-1] = 'B';
        if (x-1>=0 && y-2>=0) 
        mp[x-2][y-1] = 'B';
    }
    int main(void) {
        int n;
        while(~scanf("%d", &n)) {
            for (int i = 0; i<n; i+=2)
                for (int j = 0; j<n; j+=2) {
                    if (!mp[i][j]) solve(i, j, n);
                }
            for (int i = 0; i<n; ++i)
                for (int j = 0; j<n; ++j) {
                    if (!mp[i][j]) mp[i][j] = 'W';
                }
            for (int z = 0; z<n; ++z) printf("%s\n", mp[z]);
            zero(mp);
        }
        return 0;
    }
  • 相关阅读:
    优先队列
    Problem W UVA 662 二十三 Fast Food
    UVA 607 二十二 Scheduling Lectures
    UVA 590 二十一 Always on the run
    UVA 442 二十 Matrix Chain Multiplication
    UVA 437 十九 The Tower of Babylon
    UVA 10254 十八 The Priest Mathematician
    UVA 10453 十七 Make Palindrome
    UVA 10163 十六 Storage Keepers
    UVA 1252 十五 Twenty Questions
  • 原文地址:https://www.cnblogs.com/shuitiangong/p/12431700.html
Copyright © 2011-2022 走看看