链接:https://codeforces.com/gym/104008

A. Lily

C++ Code
#include "bits/stdc++.h"
 
using namespace std;
using i64 = long long;
 
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    if (s[i] == 'L') {
      a[min(n - 1, i + 1)] = 1;
      a[max(0, i - 1)] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 1 || s[i] == 'L') {
      cout << s[i];
    } else {
      cout << 'C';
    }
  }
}
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tt = 1;
  //cin >> tt;
  for (int _ = 1; _ <= tt; _++) {
    solve();
  }
  return 0;
}

C. Array Concatenation

C++ Code
#include <bits/stdc++.h>
 
using namespace std;
using i64 = long long;

constexpr int M = 1000000007;
 
i64 POW(i64 a, int b) {
  i64 res = 1;
  while (b) {
    if (b & 1) {
      res = res * a % M;
    }
    a = a * a % M;
    b >>= 1;
  }
  return res;
}
 
void solve() {
  auto get = [&](i64 sum, i64 presum, int k, int len) {
    i64 POW_2 = POW(2, k);
    i64 inv_2 = POW(2, M - 2);
    return (presum * POW_2 % M + len * sum % M * POW_2 % M * (POW_2 - 1 + M) % M * inv_2 % M) % M;
  };
  int n, m;
  cin >> n >> m;
  vector<i64> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  i64 presum = 0, sum = 0;
  for (int i = 0; i < n; i++) {
    sum = (sum + a[i]) % M;
    presum = (presum + sum) % M;
  }
  i64 ans1 = get(sum, presum, m, n);
  vector<i64> b(n << 1);
  for (int i = 0; i < n; i++) {
    b[i] = a[n - 1 - i];
  }
  for (int i = n; i < (n << 1); i++) {
    b[i] = a[i - n];
  }
  presum = 0, sum = 0;
  for (int i = 0; i < (n << 1); i++) {
    sum = (sum + b[i]) % M;
    presum = (presum + sum) % M;    
  }
  i64 ans2 = get(sum, presum, m - 1, n << 1);
  cout << max(ans1, ans2);
}
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tt = 1;
  //cin >> tt;
  for (int _ = 1; _ <= tt; _++) {
    solve();
  }
  return 0;
}

E. Draw a triangle

C++ Code
#include "bits/stdc++.h"
 
using namespace std;
using i64 = long long;
using i128 = __int128;
 
i128 exgcd(i128 a, i128 b, i128 &x, i128 &y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  i128 d = exgcd(b, a % b, x, y);
  i128 t = x;
  x = y;
  y = t - (a / b) * y;
  return d;
}
 
constexpr i64 N = 1E18;
 
i128 abs(i128 x) {
  if (x < 0) {
    return -x;
  }
  return x;
}
 
void print(i128 x) {
  bool ok = 0;
  if (x < 0) {
    ok = 1;
    x = -x;
  }
  i64 num1 = x / N;
  i64 num2 = x % N;
  if (ok) {
    cout << '-';
  }
  if (x < N) {
    cout << num2;
  } else {
    cout << num1 << setw(18) << setfill('0') << num2;
  }
}
 
void solve() {
  i64 x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  i128 d1 = x2 - x1;
  i128 d2 = y2 - y1;
  i128 ansx, ansy;
  if (d1 == 0) {
    cout << x1 + 1 << ' ' << y1 << '\n';
  } else if (d2 == 0) {
    cout << x1 << ' ' << y1 + 1 << '\n';
  } else {
    i128 g = exgcd(abs(d1), abs(d2), ansy, ansx);
    if (d1 < 0) {
      ansy = -ansy;
    }
    if (d2 > 0) {
      ansx = -ansx;
    }
    print(x1 + ansx);
    cout << ' ';
    print(y1 + ansy);
    cout << '\n';
  }
}
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tt = 1;
  cin >> tt;
  for (int _ = 1; _ <= tt; _++) {
    solve();
  }
  return 0;
}

M. Youth Finale

C++ Code
#include "bits/stdc++.h"
 
using namespace std;
using i64 = long long;
 
template <typename T>
class Fenwick {
 public:
  int n;
  vector<T> tree;
  Fenwick(const int &n) : n(n), tree(n) {}
  inline void modify(int pos, T x) {
    for ( ; pos <= n; pos += pos & -pos) {
      tree[pos - 1] += x;
    }
  }
  inline T get(int pos) {
    T res = 0;
    for ( ; pos > 0; pos -= pos & -pos) {
      res += tree[pos - 1];
    }
    return res;
  }
  inline T sum(int l, int r) { // (l, r]
    return get(r) - get(l);
  }
};
 
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  Fenwick<i64> f(n);
  i64 ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    ans += f.get(a[i]);
    f.modify(a[i] + 1, 1);
  }
  cout << ans << '\n';
  string s;
  cin >> s;
  i64 res = ans;
  int pos = 0; 
  int now = 0;
  for (int i = 0; i < m; i++) {
    if (s[i] == 'S') {
      res = res + n - 2 * a[pos] + 1;
    } else {
      now ^= 1;
      res = 1LL * (n - 1) * n / 2 - res;
    }
    if (now == 0) {
      pos++;
    } else {
      pos--;
    }
    pos = (pos + n) % n;
    cout << res % 10;
  }
}
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tt = 1;
  //cin >> tt;
  for (int _ = 1; _ <= tt; _++) {
    solve();
  }
  return 0;
}

原文地址:http://www.cnblogs.com/kiddingma/p/16899119.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性