首页 > 其他分享 >2022ccpc绵阳(2022 China Collegiate Programming Contest (CCPC) Mianyang Onsite)

2022ccpc绵阳(2022 China Collegiate Programming Contest (CCPC) Mianyang Onsite)

时间:2022-11-30 02:11:06浏览次数:80  
标签:Onsite tmp Mianyang 2022ccpc int nowa nowb picka pickb

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

A

#include "bits/stdc++.h"

using namespace std;

using i64 = long long;

constexpr int N = 2E5;

bool vis[N + 10][11][11];
int ans[N + 10][11][11];

void solve() {
  for (int i = 0; i <= N + 1; i++) {
    for (int j = 0; j < 11; j++) {
      for (int k = 0; k < 11; k++) {
        ans[i][j][k] = -1E9;
      }
    }
  }
  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1), b(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  function<int(int, int, int, int)> dfs = [&](int nowa, int nowb, int picka, int pickb) {  
    if (min(nowa, picka) == 0 && min(nowb, pickb) == 0) {
      return 0;
    }
    if (vis[nowa + nowb][picka][pickb]) {
      return ans[nowa + nowb][picka][pickb];
    }
    vis[nowa + nowb][picka][pickb] = 1;
    if (nowa > 0 && picka > 0) {
      int A = 1E9, B = 1E9;
      if (nowa > 1) {
        A = dfs(nowa - 2, nowb, picka - 1, pickb) + a[nowa];
      }
      if (nowb > 0 && pickb > 0) {
        B = dfs(nowa - 1, nowb - 1, picka - 1, pickb - 1) + a[nowa] - b[nowb];
      }  
      ans[nowa + nowb][picka][pickb] = max(ans[nowa + nowb][picka][pickb], min(A, B));      
    }
    if (nowb > 0) {
      int A = 1E9, B = 1E9;      
      if (nowb > 1 && pickb > 0) {
        A = dfs(nowa, nowb - 2, picka, pickb - 1) - b[nowb - 1];
      }
      if (nowa > 0) {
        B = dfs(nowa - 1, nowb - 1, picka, pickb);
      }
      ans[nowa + nowb][picka][pickb] = max(ans[nowa + nowb][picka][pickb], min(A, B));      
    }
    return ans[nowa + nowb][picka][pickb];
  };
  int ans = dfs(n, n, m, m);
  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

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

void solve() {
  int n;
  cin >> n;
  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);
  }
  i64 ans = 0;
  for (auto nex : g[1]) {
    i64 res = 0;
    function<void(int, int, i64)> dfs = [&](int cur, int pre, i64 dep) {
      res = max(res, dep);
      for (auto nex : g[cur]) {
        if (nex != pre) {
          dfs(nex, cur, dep + 1);
        }
      }
    };
    dfs(nex, 1, 1);
    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;
}

G

#include "bits/stdc++.h"

using namespace std;

using i64 = long long;

void solve() {
  int n;
  cin >> n;
  vector<int> tmp(n);
  for (int i = 0; i < n; i++) {
    cin >> tmp[i];
  }
  int ans = 0;
  int tmpn = n;
  while (1) {
    int SIZE = tmp.size();
    if (SIZE == 1) {
      break;
    }
    vector<int> p;
    for (int i = 0; i < SIZE; i++) {
      if (i == 0) {
        if (tmp[i + 1] < tmp[i]) {
          p.push_back(tmp[i]);
        }
      } else if (i == SIZE - 1) {
        if (tmp[i - 1] < tmp[i]) {
          p.push_back(tmp[i]);
        }
      } else {
        if (tmp[i + 1] < tmp[i] && tmp[i - 1] < tmp[i]) {
          p.push_back(tmp[i]);
        }
      }
    }
    tmp = p;
    ans++;
  }
  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;
}

H

#include "bits/stdc++.h"

using namespace std;

using i64 = long long;

void solve() {
  int n;
  cin >> n;
  n = 2 * n - 1;
  cout << n << '\n';
  for (int i = 1; i <= n; i++) {
    cout << i << " " << i << '\n';
  }
  cout << '\n';
}

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

M

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

//constexpr int M = 998244353;
//constexpr int M = 1000000007;

void solve() {
  string s;
  cin >> s;
  int n;
  n = s.size();
  auto check = [&](char ch, char ch1) {
    if (ch1 == 'S' && ch == 'P') {
      return 1; 
    } 
    if (ch1 == 'R' && ch == 'S') {
      return 1;
    }
    if (ch1 == 'P' && ch == 'R') {
      return 1;
    }
    return 0;
  };
  vector<int> st;
  for (int i = 0; i < n; i++) {
    while (!st.empty() && check(s[st.back()], s[i])) {
      st.pop_back();
    }
    st.push_back(i);
  }
  cout << s[st[0]] << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << fixed << setprecision(6);
  int tt = 1;
  cin >> tt;
  for (int _ = 1; _ <= tt; _++) {
    solve();
  }
  return 0;
}

标签:Onsite,tmp,Mianyang,2022ccpc,int,nowa,nowb,picka,pickb
From: https://www.cnblogs.com/kiddingma/p/16937261.html

相关文章

  • The 2021 CCPC Guilin Onsite (XXII Open Cup, Grand Prix of EDG
    https://codeforces.com/gym/103409/problem/BB.APlusBProblem—————数据结构(set)题意给你两个n位的数a,b(有前导零),c是a+b的结果(最高位的进位已省略)q次询......
  • [Editorial] 2022 CCPC Guangzhou Onsite
    2022CCPCGuangzhouOnsite大概按题目难度顺序排序。这篇题解可能没那么口胡。GYM104053EElevator相当于每个电梯在\(-x_i\),每次可以把最大的,编号最小的值减一,要求......
  • 2022CCPC桂林 (2022 China Collegiate Programming Contest (CCPC) Guilin Site)
    链接:https://codeforces.com/gym/104008A.LilyC++Code#include"bits/stdc++.h"usingnamespacestd;usingi64=longlong;voidsolve(){intn;cin......
  • 2022ccpc广州
    算是第一场xcpc(?)现场出了的题:E.Elevator 冷静分析以下就会发现其实贡献是前面的比当前数小的数和当前数的差值+1,后面的贡献是比当前小的数和当前数的差于是预处理......
  • 2022 China Collegiate Programming Contest (CCPC) Guangzhou Onsite I
    I.Infectionn=2000,我们考虑dp我们转化题意发现就是找一个连通子块然后连通块的权重就是其中任何一个点的a[i]其他都是p[i]但是对于连通块相接的点我们都要让他是(1-......
  • 2022CCPC威海站 D - Sternhalma // 状压dp + 记忆化搜索
    题目来源:2022ChinaCollegiateProgrammingContestWeihaiSiteD-Sternhalma题目链接:https://codeforces.com/gym/104023/problem/D题意在一个\(19\)个格子的六边......
  • 广州2022CCPC补题
    IInfection知识点:树上背包第一次写树上背包的题目,没想到就是在区域赛中神奇的是树上背包的复杂度,看起来是\(O(n^3)\),但是实际计算只有\(O(n^2)\)学会树上背包后可......
  • 2022CCPC威海 D. Sternhalma(记忆化搜索/状压)
    题意大概是给定一个19个格子的六边形棋盘,每个位置有一个分数,每次操作可以拿走一个棋子(不得分)或者将当前棋子跳过相邻的一个棋子(得分为跳过的棋子所在位置的分数)且将跳过的......
  • 2022CCPC威海J. Eat, Sleep, Repeat(博弈/思维)
    题目大意是给定长度为n的数组a,两个人轮流从中选一个正数将其减1。且有k个限制形如\(limit_{x_i}=y_i\),即\(x_i\)在数组中最多出现\(y_i\)次。判负的情况为:数组全为0......
  • 2022CCPC(桂林)
    我的首站本来想着练练手拿铜牌血赚打铁不亏结果保底铜牌要是G题做出来应该可以冲击一下银牌https://codeforces.com/gym/104008A.Lily签到题:所有不在L旁的字符......