当前位置:   article > 正文

Educational Codeforces Round 158 (Rated for Div. 2)_dashboard - educational codeforces round 158 (rate

dashboard - educational codeforces round 158 (rated for div. 2)

A

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4. const int maxn = 20;
  5. const int MOD = 998244353;
  6. int gcd(int a, int b) {
  7. return b ? gcd(b, a % b) : a;
  8. }
  9. int d1[maxn][maxn], d2[maxn][maxn];
  10. inline void solve() {
  11. int n, x; cin >> n >> x;
  12. vector<int>a(n);
  13. for (int i = 0; i < n; i++) {
  14. cin >> a[i];
  15. }
  16. int ans = a[0];
  17. for (int i = 1; i < n; i++) {
  18. ans = max(ans, a[i] - a[i - 1]);
  19. }
  20. ans = max(ans, 2 * (x - a[n - 1]));
  21. cout << ans << '\n';
  22. }
  23. signed main(){
  24. ios::sync_with_stdio(false);
  25. cin.tie(0);
  26. std::cout.tie(0);
  27. int t = 1;
  28. cin >> t;
  29. while (t--)
  30. solve();
  31. return 0;
  32. }

B

记得开long long,只有a[i+1]>a[i]才需要增加传送次数

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4. const int maxn = 20;
  5. const int MOD = 998244353;
  6. int gcd(int a, int b) {
  7. return b ? gcd(b, a % b) : a;
  8. }
  9. int d1[maxn][maxn], d2[maxn][maxn];
  10. inline void solve() {
  11. int n; cin >> n;
  12. vector<int>a(n);
  13. vector<int>dp(n);
  14. for (int i = 0; i < n; i++) {
  15. cin >> a[i];
  16. }
  17. dp[0] = a[0] - 1;
  18. if (n == 1) { cout << a[0] - 1 << '\n'; return; }
  19. for (int i = 1; i < n; i++) {
  20. dp[i] = dp[i - 1] + (a[i] > a[i - 1] ? a[i] - a[i - 1] : 0);
  21. }
  22. cout << dp[n - 1] << '\n';
  23. }
  24. signed main(){
  25. ios::sync_with_stdio(false);
  26. cin.tie(0);
  27. std::cout.tie(0);
  28. int t = 1;
  29. cin >> t;
  30. while (t--)
  31. solve();
  32. return 0;
  33. }

C

每次操作可使两数差距变为原来差距的一半向下取整,只最大值和最小值,这两个相等别的也相等了

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4. const int maxn = 20;
  5. const int MOD = 998244353;
  6. int gcd(int a, int b) {
  7. return b ? gcd(b, a % b) : a;
  8. }
  9. inline void solve() {
  10. int n; cin >> n;
  11. vector<ll>a(n);
  12. for (int i = 0; i < n; i++) {
  13. cin >> a[i];
  14. }
  15. if (n == 1) { cout << 0 << '\n'; return; }
  16. sort(a.begin(), a.end());
  17. if (a[0]==a[n-1]) { cout << 0 << '\n'; return; }
  18. ll sum = a[n - 1] - a[0];
  19. int ans = 0;
  20. while (sum) {
  21. sum /= 2;
  22. ans++;
  23. }
  24. cout << ans << '\n';
  25. if (ans <= n) {
  26. for (int i = 0; i < ans; i++)
  27. cout << a[0] << ' ';
  28. cout << '\n';
  29. }
  30. }
  31. signed main(){
  32. ios::sync_with_stdio(false);
  33. cin.tie(0);
  34. std::cout.tie(0);
  35. int t = 1;
  36. cin >> t;
  37. while (t--)
  38. solve();
  39. return 0;
  40. }

D

我们考虑令i为起点,那么在i左边的位置j最坏情况需要以a[j]+n-j为开头,在i右边的位置k最坏情况需要以a[k]+k-1为开头,那么如果以i为起点,需要的x为a[i]、前缀的最坏情况的最大值、后缀最坏情况的最大值中的最大值。又由于第一步要最优,那么我们只需以1~n为起点需要的x中的最小值即可,从最大值开始并不一定是最优

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4. const int maxn = 20;
  5. const int MOD = 998244353;
  6. int gcd(int a, int b) {
  7. return b ? gcd(b, a % b) : a;
  8. }
  9. inline void solve() {
  10. int n; cin >> n;
  11. vector<ll>a(n + 2);
  12. vector<ll>ml(n + 2), mr(n + 2);
  13. ll ans = 0;
  14. for (int i = 1; i <= n; i++) {
  15. cin >> a[i];
  16. ml[i] = a[i] + n - i;
  17. mr[i] = a[i] + i - 1;
  18. }
  19. ll t = 0;
  20. for (int i = 1; i <= n; i++) {
  21. t = max(ml[i], t);
  22. ml[i] = t;
  23. }
  24. ans = max(ans,t);
  25. t = 0;
  26. for (int i = n; i >= 1; i--) {
  27. t = max(mr[i], t);
  28. mr[i] = t;
  29. }
  30. ans = max(ans, t);
  31. for (int i = 1; i <= n; i++) {
  32. ans = min(ans, max(max(mr[i + 1], ml[i - 1]), a[i]));
  33. }
  34. std::cout << ans << '\n';
  35. }
  36. signed main(){
  37. ios::sync_with_stdio(false);
  38. cin.tie(0);
  39. std::cout.tie(0);
  40. int t = 1;
  41. //cin >> t;
  42. while (t--)
  43. solve();
  44. return 0;
  45. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/55080
推荐阅读
相关标签
  

闽ICP备14008679号