天天看点

CF-Codeforces Round #483 (Div. 2) A~DA-GameB-MinesweeperC-Finite or not?D-XOR-pyramid

ACM模版

A-Game

描述

CF-Codeforces Round #483 (Div. 2) A~DA-GameB-MinesweeperC-Finite or not?D-XOR-pyramid

题解

两个人依次取数, A A 每次取大的,BB 每次取小的,直到剩余一个数,输出这一个,排序即可。

代码

#include <iostream>
#include <algorithm>

using namespace std;

const int MAXN = ;

int n;
int a[MAXN];

int main(int argc, const char * argv[])
{
    while (cin >> n)
    {
        for (int i = ; i < n; i++)
        {
            cin >> a[i];
        }
        sort(a, a + n);

        cout << a[n - n /  - ] << '\n';
    }

    return ;
}
           

B-Minesweeper

描述

CF-Codeforces Round #483 (Div. 2) A~DA-GameB-MinesweeperC-Finite or not?D-XOR-pyramid

题解

扫雷游戏,注意空地情况可以理解为 0 0 。

代码

#include <iostream>
#include <cstring>

using namespace std;

const int MAXN = ;
const int DIR[][] =
{
    {-, -}, {-, }, {-, }, {, -},
    {, }, {, -}, {, }, {, }
};

struct cell
{
    int dig;
    int cnt;
    int flag;
} C[MAXN][MAXN];

int n, m;

bool judge(int x, int y)
{
    if (x >=  && y >=  && x < n && y < m)
    {
        return ;
    }

    return ;
}

void change(int x, int y)
{
    C[x][y].flag = ;
    int x_, y_;
    for (int i = ; i < ; i++)
    {
        x_ = x + DIR[i][];
        y_ = y + DIR[i][];
        if (judge(x_, y_))
        {
            C[x_][y_].cnt++;
        }
    }
}

int main(int argc, const char * argv[])
{
    while (cin >> n >> m)
    {
        getchar();

        memset(C, , sizeof(C));

        char x;
        for (int i = ; i < n; i++)
        {
            for (int j = ; j < m; j++)
            {
                x = getchar();
                if (x == '.')
                {
                    x = '0';
                }
                if (x >= '0' && x < '9')
                {
                    C[i][j].dig = x - '0';
                }
                if (x == '*')
                {
                    change(i, j);
                }
            }
            getchar();
        }

        int tag = ;
        for (int i = ; i < n; i++)
        {
            for (int j = ; j < m; j++)
            {
                if (!C[i][j].flag && C[i][j].dig != C[i][j].cnt)
                {
                    cout << "NO\n";
                    tag = ;
                    break;
                }
            }
            if (!tag)
            {
                break;
            }
        }

        if (tag)
        {
            cout << "YES\n";
        }
    }

    return ;
}
           

C-Finite or not?

数论。详解>>>

D-XOR-pyramid

DP 或 O(n2)O(n2) 暴力预处理后 O(1) O ( 1 ) 查找。详解>>>