CF-Codeforces Round #483 (Div. 2) A~D
程序员文章站
2022-05-01 08:02:39
...
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;
}
C-Finite or not?
数论。详解>>>
D-XOR-pyramid
DP 或 暴力预处理后 查找。详解>>>
推荐阅读
-
Codeforces Round #655 (Div. 2) A. Omkar and Completion
-
Codeforces Round #656 (Div. 3)D. a-Good String(递归+dfs)
-
Codeforces Round #487 (Div. 2)
-
Codeforces Round #649 (Div. 2)-B. Most socially-distanced subsequence(思维)
-
Codeforces Round #649 (Div. 2) C-Ehab and Prefix MEXs
-
Educational Codeforces Round 71 (Rated for Div. 2)E. XOR Guessing
-
Codeforces Round #659 (Div. 2) A. Common Prefixes(字符串,思维)
-
Codeforces Round #610 (Div. 2)
-
Codeforces Round #670 (Div. 2)
-
Codeforces Round #665 (Div. 2)