ACM模版

A-Game

描述

题解

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

代码

#include <iostream>
#include <algorithm>

using namespace std;

const int MAXN = 1111;

int n;
int a[MAXN];

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

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

    return 0;
}

B-Minesweeper

描述

题解

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

代码

#include <iostream>
#include <cstring>

using namespace std;

const int MAXN = 111;
const int DIR[][2] =
{
    {-1, -1}, {-1, 0}, {-1, 1}, {0, -1},
    {0, 1}, {1, -1}, {1, 0}, {1, 1}
};

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

int n, m;

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

    return 0;
}

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

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

        memset(C, 0, sizeof(C));

        char x;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; 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 = 1;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (!C[i][j].flag && C[i][j].dig != C[i][j].cnt)
                {
                    cout << "NO\n";
                    tag = 0;
                    break;
                }
            }
            if (!tag)
            {
                break;
            }
        }

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

    return 0;
}

C-Finite or not?

数论。详解>>>

D-XOR-pyramid

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