ACM模版

# A-Game

## 代码

#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

## 代码

#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;
}

# D-XOR-pyramid

DP 或 $O\left({n}^{2}\right)$$O(n^2)$ 暴力预处理后 $O\left(1\right)$$O(1)$ 查找。详解>>>

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120