A - 3.14
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
ios::sync_with_stdio(0), cin.tie(0);
string s = "1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679";
int n;
cin >> n;
cout << "3.";
for( int i = 0 ; i < n ; i ++ )
cout << s[i];
return 0;
}
B - Roulette
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
ios::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
vector<int> c(n+1);
vector<set<int>> a(n+1);
for( int i = 1 ; i <= n ; i ++ ){
cin >> c[i];
for( int j = 1 , x; j <= c[i] ; j ++ )
cin >> x , a[i].insert(x);
}
int m;
cin >> m;
vector<int> res;
for( int i = 1 ; i <= n ; i ++ ){
if( a[i].count(m) ){
if( res.empty() or c[res.back()] == c[i] ) res.push_back(i);
else if( !res.empty() and c[res.back()] > c[i] ){
res = vector<int>();
res.push_back(i);
}
}
}
cout << res.size() << "\n";
for( auto i : res )
cout << i << " ";
return 0;
}
C - Rotate Colored Subsequence
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
ios::sync_with_stdio(0), cin.tie(0);
int n , m;
cin >> n >> m;
string s;
cin >> s;
vector<int> c( n );
for( auto & i : c ) cin >> i;
map<int , deque<char>> cnt;
for( int i = 0 ; i < n ; i ++ )
cnt[ c[i] ].push_back( s[i] );
for( auto & [ k , q ] : cnt ){
char c = q.back();
q.pop_back() , q.push_front(c);
}
for( auto i : c ){
cout << cnt[i].front();
cnt[i].pop_front();
}
return 0;
}
D - LOWER
看起来需要很多数据结构。但实际上,操作 2、3 只有最后一次操作是有效的,所以记录最后一次操作位置即可。
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
ios::sync_with_stdio(0), cin.tie(0);
int n;
string s;
cin >> n >> s;
int q;
cin >> q;
vector<int> op(q), x(q);
vector<char> c(q);
int lst = -1;
for (int i = 0; i < q; i++) {
cin >> op[i] >> x[i] >> c[i];
if (op[i] != 1) lst = i;
}
for (int i = 0; i < lst; i++) {
if (op[i] != 1) continue;
s[x[i]-1] = c[i];
}
if (lst >= 0 and op[lst] == 2) {
for (auto &i: s)
if (i >= 'A' && i <= 'Z') i = i + 'a' - 'A';
} else if (lst >= 0 and op[lst] == 3) {
for (auto &i: s)
if (i >= 'a' && i <= 'z') i = i + 'A' - 'a';
}
for (int i = lst + 1; i < q; i++)
s[x[i]-1] = c[i];
cout << s;
return 0;
}
标签:AtCoder,Beginner,int,cin,long,314,lst,vector,op
From: https://www.cnblogs.com/PHarr/p/17654678.html