A 3.14

code

1
2
3
4
5
6
7
8
9
10
11
#include<bits/stdc++.h>
using namespace std;

int main()
{
string s = "1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679";
int n;
cin >> n;
cout << "3." << s.substr(0,n);
return 0;
}

B Roulette

找到目标,排序输出

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
#include<bits/stdc++.h>
using namespace std;
int c[110], b[110][40];
int main()
{
int n;
cin >> n;
for(int i = 1; i <= n; i++)
{

cin >> c[i];
for(int j = 1; j <= c[i]; j++)
{
int a;cin >> a;
b[i][a] = 1;
}
}
int x;
cin >> x;
vector<int> ans;
for(int i = 1; i <= n; i++)
{
if(b[i][x]) ans.push_back(i);
}
function<bool(int, int)> cmp = [&](int a, int b)
{
if(c[a] != c[b]) return c[a] < c[b];
else return a < b;
};
if(ans.size()){
sort(ans.begin(), ans.end(), cmp);
int cnt = 1;
for(int i = 1; i < ans.size(); i++) {
if(c[ans[i]] != c[ans[0]]) break;
cnt++;
}
cout << cnt << endl;
for(int i = 0; i < cnt; i++) cout << ans[i] << ' ';
}
else cout << 0 << endl;
return 0;
}

C Rotate Colored Subsequence

模拟,我的做法是先倒序遍历字符串记录每种颜色的最后一个,然后正序遍历,对于每种颜色的第一个赋予每种颜色的最后一个其他的赋予改颜色的前一个

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
#include<bits/stdc++.h>
using namespace std;

int main()
{
int n, m;
cin >> n >> m;
string s;
cin >> s;
s = "!" + s;
vector<int> a(n + 1);
for(int i = 1; i <= n; i++) cin >> a[i];
vector<char> first(m + 1);
for(int i = n; i >= 1; i--)
{
if(!first[a[i]]) first[a[i]] = s[i];
}
vector<char> last(m + 1);
vector<char> ans(n + 1);
for(int i = 1; i <= n; i++)
{
if(last[a[i]]) {
ans[i] = last[a[i]];
} else {
ans[i] = first[a[i]];
}
last[a[i]] = s[i];
}
for(int i = 1; i <= n; i++) cout << ans[i];
return 0;
}

D LOWER

写D的时候真的感觉自己退步很多,这种去年应该可以随便秒的
先离线,找到最后一个改变字符大小的操作,然后遍历操作序列字符该换就换,只在最后一个改变字符大小的操作的地方改变字符大小

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
#include<bits/stdc++.h>
using namespace std;

int main()
{ int n;
string s;
cin >> n >> s;
int q;
cin >> q;
int flag = 0;
int last = 0;
vector<pair<int, pair<int, char>>> a(q + 1);
for(int i = 0; i < q; i++)
{
int opt, x;
char b;
cin >> opt >> x >> b;
a[i] = {opt,{x, b}};
}
last = -1;
for(int i = q - 1; i >= 0; i--)
{
if(last == -1 && a[i].first != 1)
{
last = i;
break;
}
}
flag = 0;
for(int i = 0; i < q; i++)
{
if(a[i].first == 1) s[a[i].second.first - 1] = a[i].second.second;
else if(i == last) {
if(a[i].first == 2)transform(s.begin(),s.end(),s.begin(),::tolower);
else transform(s.begin(),s.end(),s.begin(),::toupper);
}
}
cout << s;
return 0;
}

E (概率,待补)

F (待补)

G (待补)

EX(另寻高能)