zoukankan      html  css  js  c++  java
  • Codeforces Round #254(div2)A

    很有趣的题。想到了就非常简单,想不到就麻烦了。

    其实就是一种逆向思维:最后结果肯定是这样子:

    WBWBWBWB...

    BWBWBWBW...

    WBWBWBWB...

    ...

    里面有“-”的地方改成“-”就行了。

    但是我开始是正着想的,想每个点怎么处理,这还要看它周围点的状态,越想越麻烦。。。

    这题中体现的正难则反的逆向思维很值得学习。

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<cmath>
    #include<map>
    #include<set>
    #include<vector>
    #include<algorithm>
    #include<stack>
    #include<queue>
    using namespace std;
    #define INF 1000000000
    #define eps 1e-8
    #define pii pair<int,int>
    #define LL long long int
    int n,m;
    char mp[105][105];
    int main()
    {
        //freopen("in1.txt","r",stdin);
        //freopen("out.txt","w",stdout);
        scanf("%d%d",&n,&m);
        getchar();
        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=m; j++)
            {
                scanf("%c",&mp[i][j]);
            }
            getchar();
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                if(mp[i][j]=='-')
                {
                    printf("-");
                }
                else
                {
                    if((i+j)&1)
                    {
                        printf("B");
                    }
                    else
                        printf("W");
                }
            }
            printf("
    ");
        }
        //fclose(stdin);
        //fclose(stdout);
        return 0;
    }
  • 相关阅读:
    Java——泛型、异常
    接口
    Classes
    Unit Tests
    Boundaries
    Error Handling
    Objects and Data Structures
    DB other operation
    Comments
    Functions
  • 原文地址:https://www.cnblogs.com/zywscq/p/3921017.html
Copyright © 2011-2022 走看看