The 8th Hebei Collegiate Programming Contest

A

只需要记录是不是第一次出现并且不等于'i‘即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int mod=1e6+3;
int st[30];
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
string a;cin>>a;
ll res=0;
for(int i=0;i<a.size();++i)
{
if(a[i]!='i')
{
if(!st[a[i]-'a'])res++,st[a[i]-'a']=1;
}
}
cout<<res;
}

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
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
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, m, a[N];
#define P pair<int, int>
vector<P> e[N];
void Totoro()
{
cin >> n;
priority_queue<P, vector<P>, greater<P>> q;
vector<int> ans;
for (int i = 1; i <= n; i++)
{
int l, r;
cin >> l >> r;
e[l].push_back({r, i});
}
for (int i = 1; i <= n; i++)
{
for (auto w : e[i - 1])
{
q.emplace(w);
}
while (!q.empty() && q.top().first < i - 1)
{
q.pop();
}
if (q.empty())
{
break;
}
ans.push_back(q.top().second);
q.pop();
}
cout << ans.size() << '\n';
for (auto x : ans)
{
cout << x << ' ';
}
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int t;
t = 1;
while (t--)
{
Totoro();
}
return 0;
}

G

考虑段环成为链,然后进行双指针算法。

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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int orig[3]{};
for (int i = 0; i < 3; ++i)
cin >> orig[i];
string a;
cin >> a;
const int n = a.size();
a += a;
int res = 0;
for (int s = 0; s < 2; ++s)
{
int cur[3]{orig[0], orig[1], orig[2]};
for (int i = s, j = s; i < n; i += 2)
{
while (j + 2 <= n + i && cur[a[j] - '0' + a[j + 1] - '0'])
{
cur[a[j] - '0' + a[j + 1] - '0']--;
j += 2;
}
res = max(res, j - i);
cur[a[i] - '0' + a[i + 1] - '0']++;
}
}
cout << res;
}

I

模拟题。

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
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
#define P pair<int, int>
using ll = long long;
const int mod = 1e6 + 3;
int zi_num[5], cnt, ip_num[5], cnt2;
vector<P> e[N];
void Totoro()
{
string zi;
cin >> zi;
int net_len = 0;
for (int i = 0; i < zi.size(); ++i)
{
if (zi[i] == '.')
cnt++;
else if (zi[i] == '/')
{
for (int j = i + 1; j < zi.size(); ++j)
{
net_len = net_len * 10 + zi[j] - '0';
}
break;
}
else
zi_num[cnt] = zi_num[cnt] * 10 + zi[i] - '0';
}
int n;
cin >> n;
int last = net_len % 8, com = net_len / 8;
while (n--)
{
cnt = 0;
cnt2 = 0;
memset(ip_num, 0, sizeof ip_num);
string ip;
cin >> ip;
for (int i = 0; i < ip.size(); ++i)
{
if (ip[i] == '.')
cnt2++;
else
ip_num[cnt2] = ip_num[cnt2] * 10 + ip[i] - '0';
}
bool flag = true;
for (int i = 0; i < com; ++i)
{
if (ip_num[i] != zi_num[i])
{
flag = false;
break;
}
}
if (flag && last)
{
for (int i = 8; i >= (8 - last); --i)
{
if ((ip_num[com] >> i) != (zi_num[com] >> i))
{
flag = false;
break;
}
}
}
if (flag)
cout << "YES\n";
else
cout << "NO\n";
}
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int t;
t = 1;
while (t--)
Totoro();
return 0;
}

J

由于范围很大,需要对一个1e9级别的长度的字符串进行取模是不现实的,因此需要进行快速幂,考虑使用矩阵加速地推。

初始矩阵为

1
2
3
Res 1

0 0

变化矩阵为

1
2
3
10 0

w 1

这样相乘就是

1
2
3
Res*10+w 1

0 0
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
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7;
int cnt[20];
void muti(int c[][2], int a[][2], int b[][2])
{
int tmp[2][2] = {0};
for (int i = 0; i < 2; ++i)
for (int j = 0; j < 2; ++j)
for (int k = 0; k < 2; ++k)
tmp[i][j] = (tmp[i][j] + a[i][k] * b[k][j]) % mod;
memcpy(c, tmp, sizeof tmp);
}
void qmi(int c[][2], int i, int k)
{
int res[][2] = {{1, 0},
{0, 1}};
int t[][2] = {
{10, 0},
{i, 1}};
while (k)
{
if (k & 1)
muti(res, res, t);
muti(t, t, t);
k >>= 1;
}
memcpy(c, res, sizeof res);
}
void solve()
{
int m;
cin >> m;
for (int i = 0; i < 10; ++i)
cin >> cnt[i];
int st = 0;
if (m == 1 && cnt[0])
{
cout << 0 << '\n';
return;
}
for (int i = 1; i < 10; ++i)
{
if (cnt[i])
{
st = i, cnt[i]--, m--;
break;
}
}
int o[][2] = {
{st, 1},
{0, 0}};
for (int i = 0; i < 10; ++i)
{
if (!m)
break;
if (cnt[i])
{
int bit[][2] = {
{1, 0},
{0, 1}};
int num = min(cnt[i], m);
qmi(bit, i, num);
muti(o, o, bit);
m -= num;
}
}
cout << o[0][0] << '\n';
}
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _;
cin >> _;
while (_--)
solve();
}

K

直接输出。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 200010
int n,d,h,a[N],ans=-1;
map<int,int> q;
void cb(){
cout<<"HBCPC2024";
}
signed main(){
int t;t=1;
while(t--)cb();
return 0;
}