AtCoder Beginner Contest 314 - AtCoder
A 3.14
void solve() {
string s = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679";
int n;
cin >> n;
cout << s.substr(0,n + 2) << endl;
}
B Roulette
题意:给有个 x x x,输出以下给的 n n n个数组里包含 x x x的数组(里面元素最少的),如果有多个,按升序输出
思路:先统计有 x x x的数组,有 m a p map map存下来,并且实时更新数组最小的,把map里的键值取出来放到结构体里按编号排序
struct S {
int id;
vector<int> a;
};
void solve() {
int n;
cin >> n;
vector<vector<int>> a(n);
for (int i = 0; i < n; i++) {
int m;
cin >> m;
while (m--) {
int x;
cin >> x;
a[i].push_back(x);
}
}
int k;
cin >> k;
map<int, vector<int>> mp;
int mn = INT_MAX;
for (int i = 0; i < n; i++) {
bool ok = false;
for (auto j : a[i]) {
if (j == k)ok = true;
}
if (ok) {
mn = min(mn, (int) a[i].size());
for (auto j : a[i]) {
mp[i].push_back(j);
}
}
}
vector<S> ans;
// cout << mn << endl;
for (auto [x1, x2] : mp) {
// cout << x1 << ' ' << x2.size() << endl;
if (x2.size() == mn) {
ans.push_back({x1, x2});
}
}
sort(ALL(ans), [](S x1, S x2) {
return x1.id < x2.id;
});
cout << ans.size() << endl;
for (auto [x, y] : ans)cout << x + 1 << ' ';
cout << endl;
}
C Rotate Colored Subsequence
题意:给一个数组 a a a和字符串 S S S,下标一一对应, a [ i ] a[i] a[i]相同的下标所对应的字符组成一个字符串往右移动移动一位,最后再把变换后的还原
思路:用 m a p map map来存 a [ i ] a[i] a[i]相同的字符串,在把 m a p map map存的的字符串按规则变换,最后根据数组 a a a把对应的字符输出
void solve() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<int> a(n);
for(auto &i : a)cin >> i;
map<int, string> mp;
for(int i = 0; i < n; i++) {
mp[a[i]] += s[i];
}
for(auto &[x, y] : mp) {
char op = y.back();
y.pop_back();
y = op + y;
reverse(ALL(y));
}
for(auto i : a) {
cout << mp[i].back();
mp[i].pop_back();
}
cout << endl;
}
D LOWER
题意:给一个字符串 S S S,给q次询问,每次询问给 t t t, x x x, c c c,根据规则堆字符串进行变换
-
如果 t i = 1 t _ i=1 ti=1, 将 S S S 中的 x i x _ i xi/th 字符改为 c i c _ i ci。
-
如果 t i = 2 t _ i=2 ti=2, 将 S S S 中的所有大写字母转换为小写字母(在此操作中不要使用 x i , c i x _ i,c _ i xi,ci)。
-
如果 t i = 3 t _ i=3 ti=3 ,将 S S S 中的所有小写字母转换为大写字母(此操作不要使用 x i , c i x _ i,c _ i xi,ci)。
思路:可以发现只有最后一个改变大小写(不为1)的询问会决定最终整个字符串的大小写,而在这之后如果还有修改( t t t为1)询问,还要再次修改字符串,我们找到最后一个 t t t不为 1 1 1的位置,先把这个位置,在改变大小写,再改变后面 t t t为 1 1 1的询问修改,最后输出
int n;
cin >> n;
string s;
cin >> s;
int q;
cin >> q;
vector<T > b;
while (q--) {
int t, x;
char c;
cin >> t >> x >> c;
// if (t == 1)s[x - 1] = c;
b.push_back({t, x, c});
}
// cout<<b.size()<<endl;
int pos = INT_MAX;
int ret = 0;
for (int i = b.size() - 1; i >= 0; i--) {
if (get<0>(b[i]) != 1) {
if(get<0>(b[i]) == 2)ret = 2;
else ret = 3;
break;
} else pos = i;
}
for(int i = 0; i < n; i++) {
if(get<0>(b[i]) == 1)s[get<1>(b[i]) - 1] = get<2>(b[i]);
}
if (ret == 2)for (auto &j : s)j = (char) tolower(j);
else if(ret == 3)for (auto &j : s)j = (char) toupper(j);
// else pos=i;
// cout<<pos<<endl;
for (int i = pos; i < b.size(); i++) {
s[get<1>(b[i]) - 1] = get<2>(b[i]);
}
cout << s << endl;