题目链接

A

判断两个数的差进行分类即可。注意当两数相差为正偶数时需要判断这两个数是否能分成两个相等的奇数。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
using namespace std;
#define int long long
void solve()
{
int a, b;
cin >> a >> b;
if (b - a > 0)
{
if ((b - a) % 2)//如果是奇数
{
cout << 1 << '\n';
}
else
{
if ((b - a) % 4)//如果不是4的倍数
{
cout << 2 << '\n';
}
else
cout << 3 << '\n';
}
}
else if (b - a == 0)
{
cout << 0 << '\n';
}
else//b比a小
{
if ((a - b) % 2)
{
cout << 2 << '\n';
}
else
{
cout << 1 << '\n';
}
}
}
signed main()
{
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}

B

遇到该字符串加上','即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <cstring>
using namespace std;
#define int long long
signed main()
{
string s;
cin >> s;
string ans = "";
for (int i = 0; i < s.size(); i++)
{
if (s[i] == 'c')
{
if (i + 2 < s.size() && s[i + 1] == 'j' && s[i + 2] == 'b')
{
ans += s[i];
ans += s[i + 1];
ans += s[i + 2];
ans += ',';
i += 2;
}
else
ans += s[i];
}
else
{
ans += s[i];
}
}
cout << ans;
return 0;
}

C

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;
#define int long long
int n, m, price;
signed main()
{
int i,num=0,x;
cin >> n >> m>>price;
for (i = 1; i <= n; i++)
{
cin >> x;
if (x >= price)
num++;
}
for (i = 1; i <= m; i++)
{
cin >> x;
if (x <= price)
num++;
}
cout << num << endl;

return 0;
}

L

给一串数字,选择一个子串,使得该串中严格大于这串数平均值的数最多。

先将这串数字排序,然后从小到大判断要不要把这个“新的大的”数加进来

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;
const int N = 1e6 + 10;
int n, ans = -1;
int a[N], sum[N];
signed main()
{
std::ios::sync_with_stdio(0);
std::cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++)
sum[i] = sum[i - 1] + a[i];
double avg = 0;
for (int i = 1; i <= n; i++) {
avg = (double)(sum[i]) / i;
int pos = upper_bound(a + 1, a + i + 1, avg) - a;
ans = max(ans, i - pos + 1);
}
cout << ans;
}

M

先判断“圆”的个数,注意圆周围得是‘#’而不是’.',然后判断能否由两个圆构成B图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define int long long
typedef pair <int, int> PII;
const int N = 1010;
char g[N][N];
int cntB;
vector<PII> v;
int n, m;
int dx[12] = {0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3};
int dy[12] = {0, 1, -1, 0, 1, 2, -1, 0, 1, 2, 0, 1};
bool check(int i, int j)
{
if (i - 1 < 1 || i + 4 > n || j - 2 < 1 || j + 3 > m) return false;
for (int t = 0; t < 12; t++)//判断是否有中间的圆
{
int x = i + dx[t], y = j + dy[t];
if (g[x][y] != '.') return false;
}
//判断是圆而不是一整块'.'
int cnt = 0;
for (int row = i - 1; row <= i + 4; row++)
for (int col = j - 2; col <= j + 3; col++)
if (g[row][col] == '.') cnt++;
if (cnt == 12) return true;
else return false;
}
signed main()
{
std::ios::sync_with_stdio(0);
std::cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> g[i][j];
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{

if (g[i][j] == '.')
{
if (check(i, j)) v.push_back(make_pair( i, j ));
}
}
}
for (int i = 0; i < v.size(); i++)
{
for (int j = i + 1; j < v.size(); j++)
{
int x1 = v[i].first, y1 = v[i].second;
int x2 = v[j].first, y2 = v[j].second;
if ((x1 == x2 && abs(y1 - y2) == 7) || (y1 == y2 && abs(x1 - x2) == 7)) cntB++;
}
}
cout << cntB << " " << v.size() - cntB * 2;
return 0;
}

I

两个人,一个人先拿到一串字符串,可以选择去掉开头或结尾的一个字母,要求去掉之前和去掉之后都不能是回文,问哪个人必赢。

P先拿到

  1. 如果字符串一开始就是回文,那么P必输
  2. 如果字符串不是回文,每次两个人去完之后都不是回文,直到最后拿到2个字符的字符串的人必输
    • 一开始字符串是偶数个,P必输
    • 一开始字符串是j奇数个,P必赢
  3. 非回文偶数有种特殊情况:abababab,无论删除头还是尾都会变成回文,P必输。可以与开始字符串是偶数合并。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <cstring>
using namespace std;
#define int long long
const int N = 1e6 + 10, P = 131;
int p[N], h[N], uh[N];
bool query(int l, int r)
{
return (h[r] - h[l - 1] * p[r - l + 1]) == (uh[l] - uh[r + 1] * p[r - l + 1]);
}
signed main()
{
std::ios::sync_with_stdio(0);
std::cin.tie(0);
int n, q;
string x = " ", t;
cin >> n >> q >> t;
x += t;
p[0] = 1;
for (int i = 1; i <= n; i++)
{
p[i] = p[i - 1] * P;
h[i] = h[i - 1] * P + x[i];
}
for (int i = n; i > 0; i--)
{
uh[i] = uh[i + 1] * P + x[i];
}
while (q--)
{
int l, r;
cin >> l >> r;
if (query(l, r))//如果一开始就是回文
cout << "Budada" << '\n';
else
{
if ((r - l + 1) % 2)//如果是奇数
cout << "Putata" << '\n';
else
cout << "Budada" << '\n';
}
}
return 0;
}

G

将所有点之间连起来,dijkstra计算最短路即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <iostream>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
#include <limits>

using namespace std;
#define int long long
typedef pair<int, int> PII;
vector<PII> v;
int sx, sy, tx, ty;
int v1, v2;
const int N = 1e6 + 10, M = 2 * N;
int head[M], to[M], ne[M], idx;
double w[M], dist[M];
bool st[M];
int n;
typedef pair<double, int> PII2;
priority_queue<PII2, vector<PII2>, greater<PII2>> h;
double inf = std::numeric_limits<double>::infinity();
void add(int x, int y, double t)
{
to[idx] = y, ne[idx] = head[x], w[idx] = t, head[x] = idx++;
}
double get_dist(PII a, PII b)
{
int x1 = a.first, y1 = a.second;
int x2 = b.first, y2 = b.second;
double dist = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
return dist;
}
double Dijksta(int s)
{
for (int i = 0; i <= n + 1; i++) dist[i] = inf;
dist[s] = 0;
h.push({0, s});
while (h.size())
{
PII q = h.top();
int a = q.second, b = q.first;
h.pop();
if (st[a]) continue;
st[a] = true;
for (int i = head[a]; i != -1; i = ne[i])
{
int j = to[i];
if (dist[j] - (dist[a] + w[i]) > 1e-8)
{
dist[j] = dist[a] + w[i];
h.push({ dist[j], j });
}
}
}
return dist[n + 1];
}
signed main()
{
std::ios::sync_with_stdio(0);
std::cin.tie(0);
memset(head, -1, sizeof head);
cin >> n;
v.push_back({ 0, 0 });
for (int i = 1; i <= n; i++)
{
int x, y; cin >> x >> y;
v.push_back({ x, y });
}
cin >> sx >> sy >> tx >> ty;
cin >> v1 >> v2;
//将所有的滑翔点进行连接
for(int i = 1; i <= n - 1; i++)
for (int j = i + 1; j <= n; j++)
{
double dis = get_dist(v[i], v[j]);
if (dis > 3.0 * v2)
{
add(i, j, 3.0 + (dis - 3.0 * v2) / v1);
add(j, i, 3.0 + (dis - 3.0 * v2) / v1);
}
else
{
add(i, j, dis / v2);
add(j, i, dis / v2);
}
}
//将起点和终点加入
for (int i = 1; i <= n; i++)
{
add(0, i, get_dist({ sx, sy }, v[i]) / v1);
add(i, 0, get_dist({ sx, sy }, v[i]) / v1);
double dist = get_dist({ tx, ty }, v[i]);
if (dist > v2 * 3.0)
{
add(i, n + 1, 3.0 + (dist - v2 * 3.0) / v1);
add(n + 1, i, 3.0 + (dist - v2 * 3.0) / v1);
}
else
{
add(i, n + 1, dist / v2);
add(n + 1, i, dist / v2);
}
}
double dist = get_dist({ sx,sy }, { tx,ty });
add(0, n + 1, dist / v1);
add(n + 1, 0, dist / v1);
double ans = Dijksta(0);
printf("%.12lf", ans);
return 0;
}