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

2022 China Collegiate Programming Contest (CCPC) Mianyang Onsite GCHMAD

时间:2023-09-28 11:13:50浏览次数:43  
标签:Onsite Mianyang Contest int res ll pos long push

2022 China Collegiate Programming Contest (CCPC) Mianyang Onsite

目录

VP 情况

队友告诉我题意很顺利过了两签到,对着C虚空写法,搞了一个if(n=3)while(1)的样例发现构造假了,然后马上过了,但是罚时很多然后队友过了石头剪刀布,读了A,很快想到了dp和转移方程,但不知道怎么转移好,最后结束比赛了,看了大家用记忆化搜索竟然这么好些,然后补了DM,这个D我想了很久,一直不懂怎么枚举和三分这个赔率,写了好几个版本,直到今天终于想明白了。
image

G - Let Them Eat Cake

每轮操作删掉一半的数,已得知操作次数最多只有 \(\log n\) 轮,直接模拟

int n;
const int N = 1e5 + 10;
 
void solve()
{
	cin>>n;
	int res = 0;
	vector<int> a, b;
	for(int i = 1; i <= n; i++)
	{
		int x;	cin>>x;
		b.push_back(x);
	}
	int sz = n;
	while(sz != 1)
	{
		res++;
		a = b;
		b.clear();
		int m = a.size();
		for(int i = 0; i < m; i++)
		{
			// cout<<a[i]<<"  ";
			// if(i - 1 >= 0)
			// 	cout<<a[i - 1]<<" ";
			// if(i + 1 < m)
			// 	cout<<a[i + 1]<<" ";
			// cout<<'\n';
			bool ok = false;
			if(i - 1 >= 0 && a[i - 1] > a[i])
			{
				ok = true;
			}
 
			if(i + 1 < m && a[i + 1] > a[i])
				ok = true;
			if(!ok)
				b.push_back(a[i]);
		}
		sz = b.size();
	}
	cout<<res<<'\n';
}

C - Catch You Catch Me

对于1的儿子,其答案是以其儿子为根子树的深度

int n;
const int N = 1e5 + 10;
 
int dep[N], f[N];
vector<int> e[N];
void dfs(int u, int from)
{
	dep[u] = dep[from] + 1;
	f[u] = dep[u];
	for(auto v : e[u])
	{
		if(v == from)	continue;
		dfs(v, u);
		f[u] = max(f[u], f[v]);
	}
}
void solve()
{
	cin>>n;
	for(int i = 1; i < n; i++)
	{
		int u, v;	cin>>u>>v;
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs(1, 0);
	long long res = 0;
	for(auto v : e[1])
	{
		res = res + f[v] - 1;
	}
	cout<<res<<'\n';
}

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

构造方式见代码

ll k;
int dx[] = {1, 1};
int dy[] = {1, 0};
int res[310][310];
void solve()
{
	cin>>k;
	int x = 1, y = 1;
	for(int i = 1; i <= 2 * k; i++)
	{
		x = x + dx[0];
		y = y + dy[0];
		res[x][y] = 1;
	} 	
	int n = 0;
	for(int i = 1; i <= 300; i++)
		for(int j = 1; j <= 300; j++)
			n += res[i][j];
	cout<<n<<'\n';
	for(int i = 1; i <= 300; i++)
		for(int j = 1; j <= 300; j++)
			if(res[i][j] == 1)
				cout<<i<<" "<<j<<'\n';
}

M - Rock-Paper-Scissors Pyramid

观察出有单调栈的特点,根据特点直接去模拟单调栈

const int N = 1e6 + 10;
typedef long long ll;
int n, a[N];
void solve()
{
    string s;   cin>>s;
    n = s.size();
    s = "?" + s;
    for(int i = 1; i <= n; i++)
    {
        if(s[i] == 'S') 
            a[i] = 0;
        else if(s[i] == 'P')    
            a[i] = 1;
        else 
            a[i] = 2;
    }
    stack<int> stk; stk.push(a[1]);
    for(int i = 2; i <= n; i++)
    {
        while(!stk.empty() && a[i] == (stk.top() - 1 + 3) % 3)
            stk.pop();
        stk.push(a[i]);        
    }
    while(stk.size() > 1)
        stk.pop();
    if(stk.top() == 0)
        cout<<"S";
    else if(stk.top() == 1)
        cout<<"P";
    else 
        cout<<"R";
    cout<<'\n';
}

A - Ban or Pick, What's the Trick

轮流操作,我可以选择选一个我方能力值最大的英雄,也可以禁掉对方能力值最大的英雄

\(f_{pos,i,j}\)状态就是第 \(pos\) 轮,A选了 \(i\) 个英雄,\(B\) 选了 \(j\) 个英雄,而双方禁用的英雄数量是可以确定的,用记忆化搜索写就行

const int N = 2e5 + 10;
 
typedef long long ll;
 
ll n, k;
ll a[N], b[N];
ll f[2 * N][11][11], tmp;
//  第 pos 次操作, A 选了 j 个, B 选了 p 个
ll dfs(int pos, int i, int j)
{
    if(pos == 2 * n) return 0;
    int dela = i + pos / 2 - j;
    int delb = j + (pos + 1) / 2 - i;
    if(f[pos][i][j] != tmp)
        return f[pos][i][j];
    ll res;
    if(pos % 2 == 0)
    {
        res = -1e18;
        if(dela + 1 <= n && i + 1 <= k)
            res = max(dfs(pos + 1, i + 1, j) + a[dela + 1], res);
        res = max(dfs(pos + 1, i, j), res);
    }
    else
    {
        res = 1e18;
        if(delb + 1 <= n && j + 1 <= k)
            res = min(dfs(pos + 1, i, j + 1) - b[delb + 1], res);
        res = min(dfs(pos + 1, i, j), res);
    }
    f[pos][i][j] = res;
    return res;
}
 
void solve()
{
    cin>>n>>k;
    for(int i = 1; i <= n; i++)
        cin>>a[i];
    for(int i = 1; i <= n; i++)
        cin>>b[i];
    sort(a + 1, a + 1 + n);
    sort(b + 1, b + 1 + n);
    reverse(a + 1, a + 1 + n);
    reverse(b + 1, b + 1 + n);
    memset(f, 0x3f, sizeof f);
    tmp = f[0][0][0];
    cout<<dfs(0, 0, 0)<<'\n';
    // cout<<f[1][0][0]<<'\n';
}

D - Gambler's Ruin

选择枚举一个队的赔率,三分另一个队的赔率

  1. 将两队预测胜率从小到大排序
  2. 前缀和处理
  3. 枚举A队赔率
  4. 三分另一队赔率

这个我很快想到了解法,但是一直不知道怎么处理1,2操作,写了好多个版本一直过不了样例,过了1周再写就过了

typedef long long ll;
 
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
 
map<double, ll> mp;
int n, m;
vector<pair<double, ll>> a, b;
ll sx[N], sy[N];
double res;
double f(int idx, int idy)
{
    double s1 = 1.0 * a[idx].first * sx[idx];
    double s2 = 1.0 * b[idy].first * sy[idy];    
    return 1.0 * sx[idx] + sy[idy] - max(s1, s2); 
}
void work(int idx)
{
    int l = 0, r = m - 1;
    while(l < r)
    {
        int lmid = l + (r - l) / 3;
        int rmid = r - (r - l) / 3;
        double fl = f(lmid, idx), fr = f(rmid, idx);
        if(fl <= fr)
            l = lmid + 1;
        else r = rmid - 1;
        res = max({fl, fr, res});
        // cout<<l<<" "<<r<<'\n';
    }
}
void solve()
{       
    cin>>n;
    for(int i = 1; i <= n; i++)
    {
        double p;   ll c;   cin>>p>>c;
        mp[p] += c;
    }
    a.push_back({0, 0});
    b.push_back({0, 0});
    for(auto [x, y] : mp)
    {
        if(x != 0.0)
            a.push_back({1.0 / x, y});
        if(x != 1.0)
            b.push_back({1.0 / (1.0 - x), y});
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    n = a.size(), m = b.size();
    for(int i = 0; i < n; i++)
    {
        sx[i] = a[i].second;
        if(i >= 1)  sx[i] += sx[i - 1];
    }
    for(int i = 0; i < m; i++)
    {
        sy[i] = b[i].second;
        if(i >= 1)  sy[i] += sy[i - 1];
    }
    for(int i = 0; i < n; i++)
        work(i);
    cout<<fixed<<setprecision(10)<<res<<'\n';
    return;
}

标签:Onsite,Mianyang,Contest,int,res,ll,pos,long,push
From: https://www.cnblogs.com/magicat/p/17735234.html

相关文章

  • The 2021 China Collegiate Programming Contest (Harbin) JBEIDG
    The2021ChinaCollegiateProgrammingContest(Harbin)目录The2021ChinaCollegiateProgrammingContest(Harbin)VP概况J-LocalMinimumB-MagicalSubsequenceE-PowerandModuloI-PowerandZeroD-MathmasterG-DamagedBicycleVP概况队友不应该写签到,签到......
  • AtCoder Regular Contest 127 F ±AB
    洛谷传送门AtCoder传送门非常妙的题。先直观感受一下,显然当\(M\)大到一定程度后,\([0,M]\)的所有数都能被取到。考虑\(V\getsV+Ax+By\),其中\(V+Ax+By\in[0,M]\)。如果\(x,y\)都是正数显然可以取到。如果一正一负,比如\(x>0,y\le0\),那可以先把\(V\)......
  • KEYENCE Programming Contest 2019
    A-Beginning排序以后判断一下是否为\(1,4,7,9\)即可。#include<iostream>#include<cstdio>#include<algorithm>usingnamespacestd;constintN=10;inta[N];intmain(){ for(inti=1;i<=4;i++) scanf("%d",&a[i]); sort(a+1,a+4+1......
  • NIKKEI Programming Contest 2019
    A-Subscribers最小值为\(\min(A,B)\),最大值为\(\max(A+B-n,0)\)。#include<iostream>#include<cstdio>usingnamespacestd;intn,A,B;intmain(){ scanf("%d%d%d",&n,&A,&B); printf("%d%d",min(A,B),max(A+B-n,0......
  • Dwango Programming Contest V
    A-Thumbnail直接按照题意模拟。。。#include<iostream>#include<cstdio>#include<cmath>usingnamespacestd;constintN=105;intn;inta[N];intmain(){ scanf("%d",&n); for(inti=1;i<=n;i++) scanf("%d",&a[i])......
  • M-SOLUTIONS Programming Contest
    A-SumofInteriorAngles答案为\(180(n-2)\)。#include<iostream>#include<cstdio>usingnamespacestd;intn;intmain(){ scanf("%d",&n); printf("%d",180*(n-2)); return0;}B-Sumo判断一下x的个数是否小于等于\(7\)。#......
  • Keyence Programming Contest 2020
    A-Painting每次取\(H,W\)中较大者涂就是了,输出\(\lceil\frac{n}{\max(H,W)}\rceil\)。代码:#include<iostream>#include<cstdio>usingnamespacestd;inth,w,n;intmain(){ scanf("%d%d%d",&h,&w,&n); if(h<w)swap(h,w); ......
  • NIKKEI Programming Contest 2019-2
    A-SumofTwoIntegers分奇偶讨论一下就好了,答案为\(\lfloor\frac{n-1}\{2\}\rfloor\)。#include<iostream>#include<cstdio>usingnamespacestd;intn;intmain(){ scanf("%d",&n); printf("%d",(n-1)/2); return0;}B-......
  • Tenka1 Programmer Contest 2019
    C-Stones枚举分界点爆算即可。#include<iostream>#include<cstdio>usingnamespacestd;constintN=200005;intn;chars[N];intsum[N][2];intmain(){ scanf("%d",&n); scanf("%s",s+1); sum[0][0]=sum[0][1]=0; for(inti=1;i......
  • Social Infrastructure Information Systems Division, Hitachi Programming Contest
    A-HitachiString满足条件的串即为串长为偶数且相邻两个均为为hi,直接判断即可。代码:#include<iostream>#include<cstdio>#include<cstring>usingnamespacestd;constintN=15;intn;chars[N];intmain(){ scanf("%s",s+1); n=strlen(s+1); if(n&1) ......