首页 > 其他分享 > 2022 ICPC Gran Premio de Mexico Repechaje

2022 ICPC Gran Premio de Mexico Repechaje

时间:2023-01-05 12:44:12浏览次数:65  
标签:return Premio Mexico int tt cin i64 ++ 2022

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

A. Average Walk

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

void solve() {
  int n;
  cin >> n;
  cout << min(15, (3000 + n - 1) / n);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tt = 1;
  //cin >> tt;
  while (tt--) {
    solve();
  }
  return 0;
}

B. Business Stamps

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

void solve() {
  int n, m;
  cin >> n >> m;
  int sx, sy, ex, ey;
  cin >> sx >> sy >> ex >> ey;
  sx--;
  sy--;
  ex--;
  ey--;
  vector<vector<int>> a(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      a[i][j]--;
    }
  }
  int ans = 20;
  int all = (1 << 10);
  int mx[] = {-1, +1, 0, 0};
  int my[] = {0, 0, -1, +1};
  auto check = [&](int now) {
    if (!(now & (1 << a[sx][sy]))) {
      return false;
    }
    if (!(now & (1 << a[ex][ey]))) {
      return false;
    }
    vector<vector<bool>> vis(n, vector<bool>(m));
    vis[sx][sy] = 1;
    queue<array<int, 2>> q;
    q.push({sx, sy});
    while (!q.empty()) {
      auto [x, y] = q.front();
      q.pop();
      for (int i = 0; i < 4; i++) {
        int nx = x + mx[i];
        int ny = y + my[i];
        if (nx < 0 || nx >= n) {
          continue;
        }
        if (ny < 0 || ny >= m) {
          continue;
        }
        if (vis[nx][ny]) {
          continue;
        }
        if (!(now & (1 << a[nx][ny]))) {
          continue;
        }
        vis[nx][ny] = 1;
        q.push({nx, ny});
      }
    }
    return (bool)vis[ex][ey];
  };
  for (int i = 1; i <= all; i++) {
    if (check(i)) {
      ans = min(ans, __builtin_popcountll(i));
    }
  }
  cout << ans << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tt = 1;
  //cin >> tt;
  while (tt--) {
    solve();
  }
  return 0;
}

C. Company Layoffs

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  i64 sum = 0;
  vector<i64> pre(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    pre[i + 1] = pre[i] + a[i];
  }
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    auto id = lower_bound(a.begin(), a.end(), x) - a.begin();
    cout << pre[id] + (n - id) * x << '\n';
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tt = 1;
  //cin >> tt;
  while (tt--) {
    solve();
  }
  return 0;
}

D. Denji

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

void solve() {
  int n;
  cin >> n;
  vector<i64> a(n + 1);
  vector<i64> tree;
  int now = 1;
  for (int i = 0; i < n; i++) {
    int op;
    cin >> op;
    if (op == 1) {
      i64 x;
      cin >> x;
      a[now++] = x;
      auto it = upper_bound(tree.begin(), tree.end(), x);
      tree.insert(it, x);
    } else if (op == 2) {
      i64 x;
      cin >> x;
      x = a[x];
      auto it = lower_bound(tree.begin(), tree.end(), x);
      tree.erase(it);
      now++;
    } else if (op == 3) {
      i64 x, y;
      cin >> x >> y;
      auto it = lower_bound(tree.begin(), tree.end(), a[x]);
      tree.erase(it);
      a[x] += y;
      it = upper_bound(tree.begin(), tree.end(), a[x]);
      tree.insert(it, a[x]);
      now++;
    } else {
      i64 x;
      cin >> x;
      x = a[x];
      cout << lower_bound(tree.begin(), tree.end(), x) - tree.begin() << '\n';
      now++;
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tt = 1;
  //cin >> tt;
  while (tt--) {
    solve();
  }
  return 0;
}

G. Gustavos Modern Art

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

void solve() {
  i64 n, m;
  cin >> n >> m;
  string d = "1234";
  auto get = [&](i64 x, i64 y) {
    if (d == "1234") {
      return (x - 1) * n + y;
    } else if (d == "1324") {
      return (y - 1) * n + x;
    } else if (d == "2143") {
      return (x - 1) * n + n - y + 1;
    } else if (d == "2413") {
      return (y - 1) * n + n - x + 1;
    } else if (d == "3412") {
      return (n - x) * n + y;
    } else if (d == "3142") {
      return (n - y) * n + x;
    } else if (d == "4321") {
      return (n - x) * n + n - y + 1;
    } else {
      return (n - y) * n + n - x + 1;
    }
  };
  for (int i = 0; i < m; i++) {
    char op;
    cin >> op;
    if (op == 'r') {
      char x;
      cin >> x;
      if (x == 'a') {
        swap(d[1], d[2]);
      } else if (x == 'b') {
        swap(d[0], d[1]);
        swap(d[2], d[3]);
      } else if (x == 'c') {
        swap(d[0], d[3]);
      } else {
        swap(d[0], d[2]);
        swap(d[1], d[3]);
      }
    } else {
      int x, y;
      cin >> x >> y;
      cout << get(x, y) << '\n';
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tt = 1;
  //cin >> tt;
  while (tt--) {
    solve();
  }
  return 0;
}

K. Keypad Repetitions

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

void solve() {
  int n, m;
  cin >> n >> m;
  vector<char> mp(26);
  for (int i = 0; i < 3; i++) {
    mp[i] = '2';
  }
  for (int i = 3; i < 6; i++) {
    mp[i] = '3';
  }
  for (int i = 6; i < 9; i++) {
    mp[i] = '4';
  }
  for (int i = 9; i < 12; i++) {
    mp[i] = '5';
  }
  for (int i = 12; i < 15; i++) {
    mp[i] = '6';
  }
  for (int i = 15; i < 19; i++) {
    mp[i] = '7';
  }
  for (int i = 19; i < 22; i++) {
    mp[i] = '8';
  }
  for (int i = 22; i < 26; i++) {
    mp[i] = '9';
  }
  map<string, int> st;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    string t;
    for (auto x : s) {
      t.push_back(mp[x - 'a']);
    }
    st[t]++;
  }
  for (int i = 0; i < m; i++) {
    string s;
    cin >> s;
    cout << st[s] << '\n';
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tt = 1;
  //cin >> tt;
  while (tt--) {
    solve();
  }
  return 0;
}

L. Ladybug And The Bullet Train

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

void solve() {
  int n, x;
  cin >> n >> x;
  vector<vector<int>> g(n + 1);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<int> dep(n + 1), cnt(n + 1);
  function<void(int, int)> dfs = [&](int cur, int pre) {
    cnt[cur]++;
    for (auto nex : g[cur]) {
      if (nex != pre) {
        dep[nex] = dep[cur] + 1;
        dfs(nex, cur);
        cnt[cur] += cnt[nex];
      }
    }
  };
  int ans = 2 * (n - 1);
  function<void(int, int)> get = [&](int cur, int pre) {
    for (auto nex : g[cur]) {
      if (nex == x) {
        ans -= 2 * (cnt[cur] - cnt[nex] - 1);
        ans -= dep[nex];
        ans -= 2 * (cnt[nex] - 1);
        return;
      }
    }
    for (auto nex : g[cur]) {
      if (nex != pre) {
        get(nex, cur);
      }
    }
  };
  dfs(1, 0);
  get(1, 0);
  cout << ans << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tt = 1;
  //cin >> tt;
  while (tt--) {
    solve();
  }
  return 0;
}

标签:return,Premio,Mexico,int,tt,cin,i64,++,2022
From: https://www.cnblogs.com/kiddingma/p/17027229.html

相关文章

  • 2022年12月国产数据库大事记-墨天轮
    本文为墨天轮技术社区整理的2022年12月国产数据库大事件和重要产品发布消息。目录12月国产数据库大事记(时间线)产品/版本发布兼容认证排行榜新增数据库厂商活动相关......
  • 草图大师(SketchUp)2022安装图文教程
    ​草图大师(SketchUp)是一个非常受欢迎并且易于使用的3D设计软件,它被比喻为电子设计中的“铅笔”。它的主要特点就是使用简便,人人都可以快速上手。并且可以将使用SketchUp创建......
  • 「2022年中国元宇宙产业生态图谱」重磅发布,零数科技入选!
    近日,36氪重磅发布《2022年中国元宇宙产业生态图谱》,零数科技作为优秀的元宇宙生态赋能者,入围「区块链与数字衍生经济」领域。据了解,基于2022年的深度观察走访,以及面向XR生态......
  • 2022再见, 2023你好
    岁月更迭,四季轮回。匆匆忙忙走至年末,银杏还在枝头灿烂,而风却带来了冬的气息。2022的好尚未散去,2023的凛冽已悄然来临。不知近水花先发,疑是经冬雪末销。三毛曾说:岁月......
  • HelloGitHub 最受欢迎的开源项目 Top10(2022年)
    再见2022,你好2023!HelloGitHub也随着2023年的到来,更新到了第81期开始迈向第7个年头啦。在过去的2022年,我们一共发布了12期月刊、分享了502个开源项目,Hel......
  • 2022 全球数据库排行,Snowflake又夺冠军
    byMatthiasGelbmann   Snowflake是一个数据库管理系统,在过去的一年里,它在我们的数据库引擎排名中比其他402个监控系统更受欢迎。因此,我们宣布Snowflake为202......
  • 2022年度总结
            不知不觉,2022年已经远去,时间来到了2023年,本来这篇文章要上周或者元旦写,种种原因,延迟到了现在才写这篇总结,但是还是要总结下2022年的工作,回顾下2022年当初......
  • 2022.1.4 营业日志
    感觉阳了之后没完全好啊,非常想睡觉。以后这个东西把三天放在一起吧,感觉每天都更有点多的(P3488[POI2009]LYZ-IceSkatesDescription给一张二分图,其中左边第\(i\)个点......
  • mybaits 笔记2022年8月学习笔记
    mybatis整理前期准备安装必要依赖:idea开发mybatis,如果学习测试,可以在一个直接建一个空白项目,如果是用springboot,则建议用用boot的安装捆绑方式核心依赖org.mybatis......
  • Good Bye 2022: 2023 is NEAR 补C
    A.KoxiaandWhiteboards题意:给定两个长度为n的数组,进行m次交换,第i次选择a中的一个数与bi交换,计算交换后n个数的和最大值分析:堆维护最小值进行交换#incl......