zoukankan      html  css  js  c++  java
  • Codeforces Round #607 (Div. 2) D. Beingawesomeism

    链接:

    https://codeforces.com/contest/1281/problem/D

    题意:

    You are an all-powerful being and you have created a rectangular world. In fact, your world is so bland that it could be represented by a r×c grid. Each cell on the grid represents a country. Each country has a dominant religion. There are only two religions in your world. One of the religions is called Beingawesomeism, who do good for the sake of being good. The other religion is called Pushingittoofarism, who do murders for the sake of being bad.

    Oh, and you are actually not really all-powerful. You just have one power, which you can use infinitely many times! Your power involves missionary groups. When a missionary group of a certain country, say a, passes by another country b, they change the dominant religion of country b to the dominant religion of country a.

    In particular, a single use of your power is this:

    You choose a horizontal 1×x subgrid or a vertical x×1 subgrid. That value of x is up to you;
    You choose a direction d. If you chose a horizontal subgrid, your choices will either be NORTH or SOUTH. If you choose a vertical subgrid, your choices will either be EAST or WEST;
    You choose the number s of steps;
    You command each country in the subgrid to send a missionary group that will travel s steps towards direction d. In each step, they will visit (and in effect convert the dominant religion of) all s countries they pass through, as detailed above.
    The parameters x, d, s must be chosen in such a way that any of the missionary groups won't leave the grid.
    The following image illustrates one possible single usage of your power. Here, A represents a country with dominant religion Beingawesomeism and P represents a country with dominant religion Pushingittoofarism. Here, we've chosen a 1×4 subgrid, the direction NORTH, and s=2 steps.

    You are a being which believes in free will, for the most part. However, you just really want to stop receiving murders that are attributed to your name. Hence, you decide to use your powers and try to make Beingawesomeism the dominant religion in every country.

    What is the minimum number of usages of your power needed to convert everyone to Beingawesomeism?

    With god, nothing is impossible. But maybe you're not god? If it is impossible to make Beingawesomeism the dominant religion in all

    思路:

    从小到大的判断步数够不够,检测A所在的位置

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    
    char Map[100][100];
    int r, c;
    
    
    int main()
    {
        int t;
        scanf("%d", &t);
        while(t--)
        {
            scanf("%d%d", &r, &c);
            bool flag1 = false, flag2 = false;
            for (int i = 1;i <= r;i++)
                scanf("%s", Map[i]+1);
            for (int i = 1;i <= r;i++)
            {
                for (int j = 1;j <= c;j++)
                {
                    if (Map[i][j] == 'A') flag1 = true;
                    else flag2 = true;
                }
            }
            if (!flag1)
            {
                puts("MORTAL");
                continue;
            }
            if (!flag2)
            {
                puts("0");
                continue;
            }
            for (int i = 1;i <= 4;i++)
            {
                if (i == 1)
                {
                    bool ok = false;
                    bool tmp = true;
                    for (int i = 1;i <= c;i++) if (Map[1][i] == 'P')
                    {
                        tmp = false;
                        break;
                    }
                    if (tmp) ok = true;
                    tmp = true;
                    for (int i = 1;i <= c;i++) if (Map[r][i] == 'P')
                    {
                        tmp = false;
                        break;
                    }
                    if (tmp) ok = true;
                    tmp = true;
                    for (int i = 1;i <= r;i++) if (Map[i][1] == 'P')
                    {
                        tmp = false;
                        break;
                    }
                    if (tmp) ok = true;
                    tmp = true;
                    for (int i = 1;i <= r;i++) if (Map[i][c] == 'P')
                    {
                        tmp = false;
                        break;
                    }
                    if(tmp) ok = true;
                    if (ok)
                    {
                        puts("1");
                        break;
                    }
                }
                if (i == 2)
                {
                    bool ok = false;
                    for (int i = 1;i <= r;i++)
                    {
                        bool tmp = true;
                        for (int j = 1;j <= c;j++) if(Map[i][j] == 'P')
                        {
                            tmp = false;
                            break;
                        }
                        if (tmp)
                        {
                            ok = true;
                            break;
                        }
                    }
                    for (int j = 1;j <= c;j++)
                    {
                        bool tmp = true;
                        for (int i = 1;i <= r;i++) if(Map[i][j] == 'P')
                        {
                            tmp = false;
                            break;
                        }
                        if (tmp)
                        {
                            ok = true; break;
                        }
                    }
                    if (Map[1][1] == 'A' || Map[r][1] == 'A' || Map[1][c] == 'A' || Map[r][c] == 'A') ok = true;
                    if (ok)
                    {
                        puts("2");
                        break;
                    }
                }
                if (i == 3)
                {
                    int ok = false;
                    for (int i = 1;i <= c;i++) if (Map[1][i] == 'A')
                    {
                        ok = true;
                        break;
                    }
                    for (int i = 1;i <= c;i++) if (Map[r][i] == 'A')
                    {
                        ok = true;
                        break;
                    }
                    for (int i = 1;i <= r;i++) if (Map[i][1] == 'A')
                    {
                        ok = true;
                        break;
                    }
                    for (int i = 1;i <= r;i++) if (Map[i][c] == 'A')
                    {
                        ok = true;
                        break;
                    }
                    if (ok)
                    {
                        puts("3");
                        break;
                    }
                }
                if (i == 4)
                {
                    puts("4");
                    break;
                }
            }
        }
    
        return 0;
    }
    
  • 相关阅读:
    【学习笔记】【C语言】注释
    【学习笔记】【C语言】标识符
    【学习笔记】【C语言】关键字
    【学习笔记】【C语言】第一个C程序
    【学习笔记】Xcode常见设置
    【学习笔记】Mac OS X系统介绍
    【学习笔记】虚拟机安装Mac系统
    javascript 对象 + 数组
    SpringMVC实现原理及详解
    javaweb国际化
  • 原文地址:https://www.cnblogs.com/YDDDD/p/12104908.html
Copyright © 2011-2022 走看看