CodeForces Round #555 Div.3
A. Reachable Numbers
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; const int maxn = 1e9 + 7; int N; set<int> s; int main() { scanf("%d", &N); while(s.find(N) == s.end()) { s.insert(N); N += 1; while(N % 10 == 0) N /= 10; } printf("%d\n", (int) s.size()); return 0; }
B. Long Number
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; int N; string s; int a[10]; int main() { scanf("%d", &N); cin >> s; for(int i = 1; i <= 9; i ++) { int x; scanf("%d", &x); a[i] = x; } for(int i = 0; i < N; i ++) { if(a[s[i] - '0'] > s[i] - '0') { for(int j = i; j < N; j ++) { if(a[s[j] - '0'] >= s[j] - '0') s[j] = a[s[j] - '0'] + '0'; else break; } break; } } cout << s << endl; return 0; }
C1. Increasing Subsequence (easy version)
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int N; int a[maxn]; int main() { scanf("%d", &N); for(int i = 0; i < N; i ++) scanf("%d", &a[i]); string ans = ""; int l = 0, r = N - 1, pos = 0; while(l <= r) { if(a[l] < a[r]) { if(a[l] > pos) { pos = a[l]; l ++; ans += 'L'; } else if(a[r] > pos) { pos = a[r]; r --; ans += 'R'; } else break; } else { if(a[r] > pos) { pos = a[r]; r --; ans += 'R'; } else if(a[l] > pos) { pos = a[l]; l ++; ans += 'L'; } else break; } } printf("%d\n", ans.length()); cout << ans << endl; return 0; }
C2. Increasing Subsequence (hard version)
代码(在两边一样的情况下只能选左或右跑了):
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int N; int pos = 0; int a[maxn]; string ans1 = "", ans2 = "", ans = ""; string Left(int st, int en, string s) { string t = s; int l = st, r = en; while(l <= r) { if(a[l] > pos) { pos = a[l]; l ++; t += 'L'; } else break; } return t; } string Right(int st, int en, string s) { string t = s; int l = st, r = en; while(l <= r) { if(a[r] > pos) { pos = a[r]; r --; t += 'R'; } else break; } return t; } int main() { scanf("%d", &N); for(int i = 0; i < N; i ++) scanf("%d", &a[i]); int l = 0, r = N - 1; int tp = 0; while(l <= r) { if(a[l] < a[r]) { if(a[l] > pos) { pos = a[l]; l ++; ans += 'L'; } else if(a[r] > pos) { pos = a[r]; r --; ans += 'R'; } else break; } else if(a[l] > a[r]) { if(a[r] > pos) { pos = a[r]; r --; ans += 'R'; } else if(a[l] > pos) { pos = a[l]; l ++; ans += 'L'; } else break; } else { int poo = pos; ans1 = ans, ans2 = ans; ans1 = Left(l, r, ans); pos = poo; ans2 = Right(l, r, ans); if(ans1.length() > ans2.length()) //cout << ans1 << endl; ans = ans1; else //cout << ans2 << endl; ans = ans2; break; } } printf("%d\n", ans.length()); cout <<ans <<endl; return 0; } /* 15 37504 79054 80071 95721 135743 164345 189260 190810 191657 196168 200000 200000 190810 190018 185437 */
E. Minimum Array
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int N; int a[maxn], c[maxn]; int main() { multiset<int> s; scanf("%d", &N); for(int i = 1; i <= N; i ++) scanf("%d", &a[i]); for(int i = 1; i <= N; i ++) { int x; scanf("%d", &x); s.insert(x); } for(int i = 1; i <= N; i ++) { int now = N - a[i] % N; multiset <int>::iterator it = s.lower_bound(now); if(it == s.end()) it = s.begin(); c[i] = (a[i] + (*it)) % N; s.erase(it); } for(int i = 1; i <= N; i ++) printf("%d%s", c[i], i != N ? " " : "\n"); return 0; }
省赛之后脑子一点都不 丝滑? 暴躁 coder 在线可爱