AtCoder Beginner Contest 258

AtCoder Beginner Contest 258

Link

A - When?

模拟即可.

点击查看代码
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int n; scanf("%d", &n);
  int x = 21, y = 0;
  x += n / 60, y += n % 60;
  printf("%02d:%02d", x, y);
  return 0;
}

B - Number Box

模拟即可.

点击查看代码
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }

int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n; cin >> n;
  vector<string> s(n);
  for(int i = 0; i < n; i ++ ) {
    cin >> s[i];
  }

  array<int, 2> pos = {0, 0};
  for(int i = 0; i < n; i ++ ) {
    for(int j = 0; j < s[i].size(); j ++ ) {
      if(s[pos[0]][pos[1]] < s[i][j]) {
        pos = {i, j};
      }
    }
  }


  auto dfs = [&] (array<int, 2> p) {
    string ans;
    for(int i = 0; i < 8; i ++ ) {
      int x = p[0], y = p[1];
      string res; res.push_back(s[p[0]][p[1]]);
      for(int j = 0; j < n - 1; j ++ ) {
        x += dx[i], y += dy[i];
        x = (x + n) % n, y = (y + n) % n;
        res.push_back(s[x][y]);
      }
      ans = max(ans, res);
    }
    return ans;

  };

  string ans(n, '0');
  for(int i = 0; i < n; i ++ ) {
    for(int j = 0; j < n; j ++ ) {
      if(s[pos[0]][pos[1]] == s[i][j]) {
        ans = max(ans, dfs({i, j}));
      }
    }
  }
  cout << ans << "\n";

  return 0;
}

C - Rotation

模拟即可.

点击查看代码
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include <debugger>
#else
#define debug(...) 42
#endif

template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, q; cin >> n >> q;
  string s; cin >> s;
  int st = 0;
  while(q -- ) {
    int op; cin >> op;
    if(op == 1) {
      int x; cin >> x;
      st -= x;
      st = (st % n + n) % n;
    } else {
      int x; cin >> x;
      cout << s[(st + x - 1 + n) % n] << "\n";
    }
  }
  return 0;
}

D - Trophy

模拟即可.

点击查看代码
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, x; cin >> n >> x;
  ll ans = INT64_MAX;
  vector<array<int, 2> > a(n);
  for(auto &[x, y]: a) cin >> x >> y; 
  ll now = 0;
  for(int i = 0; i < n && i < x; i ++ ) {
    now += a[i][0] + a[i][1];
    ll ret = now;
    int cnt = x - i - 1;
    chkmin(ans, ret + 1ll * a[i][1] * cnt);
  }
  cout << ans << "\n";
  return 0;
}

E - Packing Potatoes

题意: 有 \(10^{1000000}\) 个马铃薯,第 \(i\) 个马铃薯的重量是 \(w_{i \mod n}\),现在将这些马铃薯按顺序装入袋子中,当每个袋子中的马铃薯的重量大于等于 \(x\) 的时候,需要更换新的袋子,求第 \(k\) 个袋子中的马铃薯的个数。

点击查看代码
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include <debugger>
#else
#define debug(...) 42
#endif

template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  ll n, q, x; cin >> n >> q >> x;
  vector<ll> w(n * 2 + 1);
  for (int i = 0; i < n; i ++ ) {
    cin >> w[i]; w[i + n] = w[i];
  }
  for(int i = n * 2 - 1; i -- ; ) {
    w[i] += w[i + 1];
  }

  ll r = x % w[n];

  vector<ll> sz(n), jump(n);

  for (int i = n, j = n * 2; i -- ; ) {
    while(i < j && w[i] - w[j - 1] >= r) {
      -- j;
    }
    sz[i] = (x / w[n]) * n + j - i;
    jump[i] = j % n;
  }

  vector<ll> t(n, -1), seq;

  ll offset, cycle;

  for(int i = 0; ; i = jump[i]) {
    if(~t[i]) {
      offset = t[i];
      cycle = seq.size() - offset;
      break;
    }
    t[i] = seq.size();
    seq.emplace_back(sz[i]);
  }
  // cout << 
  // cout << seq[0] << "\n";
  while(q -- ) {
    ll k; cin >> k; 
    -- k;
    cout << seq[k < offset ? k : offset + (k - offset) % cycle] << "\n";
  }


  return 0;
}
posted @ 2022-09-20 12:43  ccz9729  阅读(31)  评论(0编辑  收藏  举报