首页 > 其他分享 >2022icpc西安(The 2022 ICPC Asia Xian Regional Contest)

2022icpc西安(The 2022 ICPC Asia Xian Regional Contest)

时间:2022-11-29 16:02:21浏览次数:42  
标签:Contest int res Regional i64 min 2022 c2 c1

C

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

void solve() {
  i64 a, b, c;
  cin >> a >> b >> c;
  i64 tmp = 1;
  i64 ans = c * b;
  int cnt = 0;
  while (tmp < c) {
    ans = min(ans, (c + tmp - 1) / tmp * b + cnt * a);
    tmp *= 2;
    cnt++;
  }
  ans = min(ans, (c + tmp - 1) / tmp * b + cnt * a);
  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;
}

G

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

static constexpr int p[2] = {223333333, 773333333};
static constexpr int mod[2] = {1000000033, 1000002233};

constexpr int N = 1E5;

i64 pw[2][N + 10];

void init() {
  pw[0][0] = 1;
  pw[1][0] = 1;
  for (int i = 1; i <= N; i++) {
    pw[0][i] = pw[0][i - 1] * p[0] % mod[0];
    pw[1][i] = pw[1][i - 1] * p[1] % mod[1];
  }
}

class StringHash {
 public:
  vector<vector<i64>> h;
  StringHash() : h(2, vector<i64>(1)) {}
  inline void push_back(char ch) {
    h[0].push_back((h[0].back() * p[0] + ch) % mod[0]);
    h[1].push_back((h[1].back() * p[1] + ch) % mod[1]);
  }
  inline i64 get(int l, int r) {
    return (h[0][r + 1] - h[0][l] * pw[0][r - l + 1] % mod[0] + mod[0]) % mod[0] + (((h[1][r + 1] - h[1][l] * pw[1][r - l + 1] % mod[1] + mod[1]) % mod[1]) << 30);
  }
};

void solve() {
  int n;
  cin >> n;
  set<i64> mp;
  vector<string> a(n);
  vector<StringHash> h(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<pair<int, string>> b(n);
  for (int i = 0; i < n; i++) {
    int len = a[i].size();
    b[i].first = len;
    b[i].second = a[i];
  }
  sort(b.begin(), b.end(), greater<>());
  for (int i = 0; i < n; i++) {
    int len = b[i].second.size();
    StringHash tmph;
    for (int j = 0; j < len; j++) {
      tmph.push_back(b[i].second[j]);
    }
    mp.insert(tmph.get(0, len - 1));
    h[i] = tmph;
  }
  for (int i = 0; i < n; i++) {
    int len = b[i].first;
    bool ok = 1;
    for (int j = 1; j <= len; j++) {
      for (int k = 0; k + j - 1 < len; k++) {
        if (mp.find(h[i].get(k, k + j - 1)) == mp.end()) {
          ok = 0;
          break;
        }
      }
      if (!ok) {
        break;
      }
    }
    if (ok) {
      cout << len << '\n';
      return;
    }
  }
  cout << 0 << '\n';
}

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

E

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

i64 f(i64 x) {
  if (x == 0) {
    return 1;
  }
  if (x > 0 && x % 3 == 0) {
    return f(x / 3) + 1;
  }
  return f(x - 1) + 1;
}

void solve() {
  i64 l, r;
  cin >> l >> r;
  i64 ans = max(f(r), f(l));
  vector<int> R;
  i64 tmpr = r;
  while (tmpr) {
    R.push_back(tmpr % 3);
    tmpr /= 3;
  }
  int SIZE = R.size();
  reverse(R.begin(), R.end());
  for (int i = 0; i < SIZE; i++) {
    if (R[i] == 0) {
      continue;
    }
    i64 p = 0;
    for (int j = 0; j < i; j++) {
      p = p * 3 + R[j];
    }
    p = p * 3 + R[i] - 1;
    for (int j = i + 1; j < SIZE; j++) {
      p = p * 3 + 2;
    }
    if (p >= l) {
      ans = max(ans, f(p));
    }
  }
  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;
}

F

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

void solve() {
  i64 n, c1, c2;
  cin >> n >> c1 >> c2;
  vector<string> a(n);
  i64 ans = 0;
  for (int i = 0; i < n; i++) {
    i64 res = 1E9;
    cin >> a[i];
    set<char> ST;
    for (auto x : a[i]) {
      ST.insert(x);
    }
    if ((int) ST.size() == 3) {
      res = min(res, c1 * 3);
      res = min(res, c2 * 3);
      res = min(res, 2 * c2 + c1);
      res = min(res, 2 * c1 + c2);
    }
    if ((int) ST.size() == 2) {
      res = min(res, c2 + c1);
      res = min(res, c1 * 3);
      res = min(res, c2 * 3);
      res = min(res, c2 * 2);
      res = min(res, 2 * c2 + c1);
      res = min(res, 2 * c1 + c2);
    }
    if ((int) ST.size() == 1) {
      res = min(res, c2 + c1);
      res = min(res, c1 * 3);
      res = min(res, c2 * 2);
      res = min(res, c2 * 3);
      res = min(res, 2 * c2 + c1);
      res = min(res, 2 * c1 + c2);
    }
    ans += res;
  }
  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;
}

J

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  if (a[n - 1] <= 0) {
    cout << 0 << '\n';
    return;
  }
  if (a[n - 1] > 0) {
    if (a[n - 2] < 0) {
      cout << a[n - 1] << '\n';
      return;
    }
    cout << a[n - 1] + a[n - 2] << '\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

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

void solve() {
  int n;
  cin >> n;
  vector<vector<int>> g(n + 1);
  vector<int> d(n + 1);
  for (int i = 2; i <= n; i++) {
    int u;
    cin >> u;
    d[u]++;
    g[i].push_back(u);
  }
  vector<int> dep(n + 1);
  queue<int> q;
  for (int i = 1; i <= n; i++) {
    if (d[i] == 0) {
      q.push(i);
      dep[i] = 1;
    }
  }
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (auto nex : g[cur]) {
      dep[nex] = dep[cur] + 1;
      if (--d[nex] == 0) {
        q.push(nex);
      }
    }
  }
  int ans = 2E9;
  vector<int> val(n + 1);
  for (int i = 1; i <= n; i++) {
    val[dep[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    ans = min(ans, val[i] + i - 1);
  }
  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;
}

标签:Contest,int,res,Regional,i64,min,2022,c2,c1
From: https://www.cnblogs.com/kiddingma/p/16935609.html

相关文章

  • 2022腾讯全球数字生态大会【存储专场】它来了|预约有礼
    它来了!它来了!2022腾讯全球数字生态大会【存储专场】它来了!作为腾讯集团产业互联网规格最高、规模最大、覆盖面最广的年度盛会今年存储专场与您一起探讨分布式高性能存储......
  • 网关Zuul+route+Filter笔记20221129
    一、ek20141、pom.xml<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starte......
  • 浅谈CVE-2022-22965漏洞成因(六)
    前言:记录一篇自己入门java安全的故事,捋一下思路,轻量知识,重在调试!.这篇文章四个部分:引入篇:整理一下CVE-2022-22965漏洞的来龙去脉基础篇:回顾Java中一些基础的内容调......
  • NOIP2022 游记
    怕不是真要NOIP退役了……Day-10果断停课,回归机房。(但whk已经在上三角函数了……血亏,以后再补吧)补了补之前的题目。晚上模拟赛爆零了!!好耶(埋伏笔)Day-9~Day-5......
  • NOI2022游记
    黄昏降临了。天边被染成深红,橘色层云密布,橙白交界之线宛如辐射般向四方伸展;木林斜立,投下一片片阴影;暮光弥散,旅人的脸颊被映上朱红。咆哮着、吐着白雾,独眼巨兽缓缓向卡农滚......
  • NOIP2022 VP 游寄
    考前给大家说一下我糟糕的模拟赛成绩:\(\operatorname{rk}29\)(总人数\(32\))感觉NOIP2022无望了。(最后再说一句,我的CSP/S太菜了,才\(165\)分,无缘NOIP正式名额,只......
  • 2022-11-29 语言小知识
    英语(也叫英文)(English)从属于印欧语系里面的西日耳曼语支,具体的起源则是由古代从欧洲大陆迁徙到大不列颠岛的撒克逊、盎格鲁和朱特部落的日耳曼人他们原来说的语言慢慢演化而......
  • KubeSphere 社区双周报 | KubeKey v3.0.2 发布 | 2022-11-24
    KubeSphere从诞生的第一天起便秉持着开源、开放的理念,并且以社区的方式成长,如今KubeSphere已经成为全球最受欢迎的开源容器平台之一。这些都离不开社区小伙伴的共同努力......
  • 预告|2022 星策 Summit 首批嘉宾确认,精彩内容抢先看!
    StartTogether,StarTogether,一起开始,一起闪耀!星策社区年度最大峰会来啦!2022星策Summit是由星策开源社区主办、思否社区协办,面向企业管理层、CTO、CEO、AI工程师、开发......
  • 2022年鲜为人知的CSS 特性了解起来~
    前言随着CSS的不断发展,一些很酷且有用的属性要么完全被忽视,要么由于某种原因不像其他常见属性那样被开发者熟练应用。这篇文章我们将一起学习那些CSS中陌生但非常有用的CS......