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

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

时间:2023-09-15 20:45:01浏览次数:48  
标签:Onsite Mianyang Contest int cb tt long stk ca

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

https://codeforces.com/gym/104065
昨天女队vp了一下,赛时4题223罚时
A是一个dp,学妹已经写的差不多了,就是转移方向错了(给点时间应该能d出来)牛的牛的。我就看了点签到,又是作为蟑螂乱爬的一天

A. Ban or Pick, What's the Trick

记忆化搜索。
状态:\(dp_{i, j, k}\) 表示进行到第 \(i\) 轮,\(A\) 选了 \(j\) 个, \(B\) 选了 \(k\) 个的 \(s_A-s_B\) 的值,然后二者都是从大往小来选(贪心),所以当前选的数也可以通过状态来计算出他所在的下标。

#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 5;
int n, m, a[N], b[N], f[N][11][11];
bool vis[N][11][11];

int dfs (int x, int ca, int cb) {
    if (x >= 2 * n) return 0;
    if (vis[x][ca][cb])   return f[x][ca][cb];
    vis[x][ca][cb] = true;
    int aa = x / 2 - cb + ca + 1, bb = (x + 1) / 2 - ca + cb + 1, &t = f[x][ca][cb];
    t = dfs (x + 1, ca, cb); //不选
    if (x % 2 == 0) { //A
        if (aa <= n && ca < m)  t = max (t, dfs (x + 1, ca + 1, cb) + a[aa]);
    }   
    else { //B
        if (bb <= n && cb < m)  t = min (t, dfs (x + 1, ca, cb + 1) - b[bb]);
    }
    return t;
}

int main () {
    scanf ("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)    scanf ("%d", &a[i]);
    for (int i = 1; i <= n; i++)    scanf ("%d", &b[i]);
    sort (a + 1, a + n + 1, greater<int>());
    sort (b + 1, b + n + 1, greater<int>());
    printf ("%d\n", dfs (0, 0, 0));
}

C. Catch You Catch Me

签到。答案为所有深度为1的点的子树最大深度之和。

#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int N = 1e5 + 5, M = N * 2;
int n, h[N], e[M], ne[M], idx;
ll dep[N], ans, tt;
bool d[N];

void add (int a, int b) {
    e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}

int dfs (int u, int fa) {
    dep[u] = dep[fa] + 1, tt = max (tt, dep[u]);
    for (int i = h[u]; ~i; i = ne[i]) {
        int j = e[i];
        if (j == fa)    continue;
        dfs (j, u);
    }
    return tt;
}

int main () {
    memset (h, -1, sizeof h);
    scanf ("%d", &n);
    for (int i = 1; i <= n; i++) {
        int a, b;
        scanf ("%d%d", &a, &b);
        add (a, b), add (b, a);
        if (a == 1) d[b] = true;
        if (b == 1) d[a] = true;
    }

    for (int i = 1; i <= n; i++) {
        if (d[i])    tt = 1, ans += dfs (i, 1);// cout << i << ' ' << tt << endl;
    }
    printf ("%d\n", ans);
}

G. Let Them Eat Cake

模拟。因为每次至少会删掉一半的数,所以最多进行log次
暴力模拟即可

#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int N = 1e5 + 5;
int n, a[N], ans;
bool vis[N];

int main () {
    scanf ("%d", &n);
    vector<int> v;
    for (int i = 1; i <= n; i++)    scanf ("%d", &a[i]), v.push_back (a[i]);
    while (1) {
        vector<int> tt;
        n = v.size ();
        if (n == 1) break;
        if (v[0] > v[1])    tt.push_back (v[0]);
        for (int i = 1; i < n - 1; i++) {
            if (v[i] > v[i+1] && v[i] > v[i-1]) tt.push_back (v[i]);
        }
        if (v[n-1] > v[n-2])    tt.push_back (v[n-1]);
        v.clear ();
        for (auto i : tt)   v.push_back (i);// cout << i << ' ';
        //cout << endl;
        ans++;
        if (v.size () == 1)   break;
    }
    
    printf ("%d\n", ans);
}

H - Life is Hard and Undecidable, but...

构造一条斜线即可,然而我们想了好久qaq

#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main () {
    int n;
    cin >> n;
    cout << 2 * n - 1 << endl;
    for (int i = 1; i < 2 * n; i++) cout << i << ' ' << i << endl;
}

M. Rock-Paper-Scissors Pyramid

栈模拟,维护栈内始终是 a 赢 b 的关系
最终答案就是栈底

#include <bits/stdc++.h>
#define ll long long

using namespace std;

bool check (char a, char b) { //a输给b
    if (a == b) return true;
    if (a == 'S')   return b == 'R';
    if (a == 'P')   return b == 'S';
    return b == 'P';
}

void solve () {
    string s;
    cin >> s;
    stack <char> stk;
    stk.push (s[0]);
    for (int i = 1; i < s.size (); i++) {
        while (stk.size () && check (stk.top (), s[i])) stk.pop ();
        stk.push (s[i]);
    }

    while (stk.size () > 1) stk.pop ();
    cout << stk.top () << endl;
}

int main () {
    int t;
    cin >> t;
    while (t--) solve ();
}

剩下两题看半天题解看不懂5555我好菜

标签:Onsite,Mianyang,Contest,int,cb,tt,long,stk,ca
From: https://www.cnblogs.com/CTing/p/17705879.html

相关文章

  • 《The 2023 Guangdong Provincial Collegiate Programming Contest》vp记录
    队伍配置:\(Shui\_dream\)\(gaosichensb\)和我这个菜鸡。膜拜另外两个大佬赛况:\(PS:\)看高二的在那边打感觉挺有趣的我们也跑过来打了。首先我把\(A\)签到题给签了,然后去看\(D\),\(gsc\)去看\(C\),这时候\(lyq\)大佬还没有加入战场,还在调自己的题,不过问题不大。我......
  • AtCoder Grand Contest 063
    PrefaceAGC好难啊,这场补完最近就没啥比赛好补了,接下来去训练下专题吧像C题这种美妙的人类智慧题感觉以我的脑子一辈子也想不出来wwwA-MexGame对于任意一段前缀,我们可以求出对应的每个人的操作次数以及每个人拥有的位置数考虑Alice的最优策略一定是从小到大地放入Bob对应......
  • AtCoder Grand Contest 058 F Authentic Tree DP
    洛谷传送门AtCoder传送门人生中第一道AtCoder问号题。设\(P=998244353\)。注意到\(f(T)\)的定义式中,\(\frac{1}{n}\)大概是启示我们转成概率去做。发现若把\(\frac{1}{n}\)换成\(\frac{1}{n-1}\)答案就是\(1\),所以\(\frac{1}{n}\)大概是要转成点数之类的。......
  • The 2021 ICPC Asia Macau Regional Contest
    目录写在前面AKFCGI写在最后写在前面比赛地址:https://codeforces.com/gym/104373当了一场口胡选手。我是彩笔。以下按个人向难度排序。A随便找条路径,检查路径是否满足条件,满足则直接输出,否则倒序输出。CodebyYRMrSu:#include<bits/stdc++.h>#defineLLlonglongusing......
  • AtCoder Beginner Contest 319 全部题解
    AtCoderBeginnerContest319全部题解ALegendaryPlayers该题只需使用判断来写出所有的答案,注意不要复制错。#include<bits/stdc++.h>usingnamespacestd;strings;intmain(){ cin>>s; if(s=="tourist")cout<<3858<<endl; if(s=="ksun4......
  • The 2020 ICPC Asia Shenyang Regional Programming Contest DFIK
    The2020ICPCAsiaShenyangRegionalProgrammingContest-CodeforcesDFIKD.JourneytoUn'Goro思路:思维+搜索一开始以为是构造,好吧但是是搜索。我们先考虑什么时候是最大值?首先考虑,题目要求我们从\(i->j\)且红色的数量是奇数被认为是好的。那么我们考虑记录\(p......
  • 2022-2023 ACM-ICPC German Collegiate Programming Contest (GCPC 2022)
    A.AlternativeArchitecture当倾斜放置时,一定可以构成直角三角形。枚举高用勾股定理算出底,然后在利用相似三角形即可算出另一条构成的直角三角形的边长,此时判断边是否都是整数即可。原图实际上点在格子上,一个常见的套路是边减一就可以转换成点在定点上。#include<bits/stdc+......
  • AtCoder Beginner Contest 044 C (背包DP、思维、*1583)
    C-TakandCards题意:给定$N$个正整数$x_1,x_2,\cdot\cdot\cdot,x_n$和一个正整数$A$,问从中选择$k$个数\((k>0)\),满足:这$k$个数的平均值是$A$的方案总数是多少?思路:......
  • Codeforces Round 819 (Div. 1 + Div. 2) and Grimoire of Code Annual Contest 2022
    给一个长为\(n\)的正整数数组,执行以下操作严格一次。选择\(l,r,(1\leql<r\leqn)\),任意一个正整数\(k\)。重复\(k\)次:让\([l,r]\)的数组成环,按顺时针走一次。希望\(a_n-a_1\)最大,找到这个数。分类讨论题。先判断\(n\)为\(1\)时\(a_n-a_1\)......
  • 2019-2020 ACM-ICPC Brazil Subregional Programming Contest
    D.DenouncingMafia给定一颗树,然后给定\(k\)个起点,对于每个起点来说,从该点到根节点的一条链都会被染色,求最多有几个点会被染色\(3\leqn\leq1e5,1\leqk\leqn\)题解我们贪心的来看,起点一定会选择在叶子节点,假设叶子节点的数量为\(cnt\),所以如果\(k\geqcnt\),那么......