AtCoder Beginner Contest 314
AtCoder Beginner Contest 314 - AtCoder
A - 3.14 (atcoder.jp)
题目提供了100位,所以直接用字符串输出
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679";
int n;
cin >> n;
for(int i = 0;i < n + 2;i ++)
cout << s[i];
return 0;
}
B - Roulette (atcoder.jp)
感觉还是题意比较抽象,看懂了就能模拟出来了.
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> C[n + 1];
for(int i = 1;i <= n;i ++){
int x;
cin >> x;
for(int j = 0;j < x;j ++){
int y;
cin >> y;
C[i].emplace_back(y);
}
}
int X;
cin >> X;
set<pair<int,int>> s;
for(int i = 1;i <= n;i ++){
if(std::find(C[i].begin(), C[i].end(),X) != C[i].end()){
s.insert({C[i].size(),i});
}
}
if(s.size()){
int cnt = 0;
auto x = s.begin()->first;
vector<int> ans;
for(auto [i,j] : s){
if(i == x)
ans.emplace_back(j),cnt++;
else
break;
}
cout << cnt << '\n';
for(auto i : ans )
cout << i << ' ';
}else
cout << "0\n";
return 0;
}
C - Rotate Colored Subsequence (atcoder.jp)
要把相同颜色都往左移一位,最后面的要移到前面来,所以我们可以预处理出相同颜色的字符串,然后最后一位放前面,我这里是逆转了一下,方便使用\(string.pop\_back()\),最后就是将对应颜色的放进去就好了
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,m;
string s;
cin >> n >> m >> s;
vector<int> c(n + 1);
s = " " + s;
for(int i = 1;i <= n;i ++) cin >> c[i];
vector<string> sc(m + 1, "");
for(int i = 1;i <= n;i ++){
sc[c[i]] += s[i];
}
for(auto &i : sc){
i = i.back() + i.substr(0,i.size() - 1);
std::reverse(i.begin(), i.end());
}
string ans = "";
for(int i = 1;i <= n;i ++){
ans += sc[c[i]].back();
sc[c[i]].pop_back();
}
cout << ans << '\n';
return 0;
}
D - LOWER (atcoder.jp)(离线思想)
不管前面大小写翻转了几次,只有最后一次的大小写翻转能决定之前的字符串,之后因为没有翻转了,所以单点修改即可,因为要找到最后一次大小写修改,所以我们要用到离线思想,即把每次操作存起来判断,最后再处理结果
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
string s;
cin >> n >> s >> m;
vector<int> T(m + 1),X(m + 1);
vector<char> C(m + 1);
for(int i = 1;i <= m;i ++)
cin >> T[i] >> X[i] >> C[i];
int f = 1;
int pos = 0;
for(int i = m;i >= 1;i --){
if(T[i] != 1){
f = T[i];
pos = i;
break;
}
}
if(pos > 1){
for(int i = 1;i < pos;i ++){
if(T[i] == 1){
s[--X[i]] = C[i];
}
}
}
if(f == 2)std::transform(s.begin(), s.end(),s.begin(),::tolower);
else if(f == 3) std::transform(s.begin(), s.end(),s.begin(),::toupper);
for(int i = pos + 1;i <= m;i ++){
if(T[i] == 1){
s[--X[i]] = C[i];
}
}
cout << s << '\n';
return 0;
}