首页 > 其他分享 >Codeforces Round 905 - div.3(A B C D E)

Codeforces Round 905 - div.3(A B C D E)

时间:2023-10-23 12:11:06浏览次数:26  
标签:cnt shu 905 int ++ Codeforces ss ans div.3

目录

Codeforces Round 905 (Div. 3)

A. Morning

模拟光标移动即可

void solve(){
	string ss;
	cin >> ss;
	char ch = '1';
	int ans = 0;
	for(auto c : ss){
		if(c != ch){
			int x = c, y = ch;
			if(c == '0') x = '9' + 1;
			if(ch == '0') y = '9' + 1;
			ans += abs(x - y);
			ch = c;
		}
		++ ans;
	}
	cout << ans << '\n';
	return ;
}

B. Chemistry

先统计每种字符出现的次数,再统计字符出现次数为奇数的个数 \(cnt\),如果 $cnt \le k + 1 $ 则可以满足要求,反之不行

void solve(){
	int n, k;
	string ss;
	cin >> n >> k >> ss;
	vector<int> cnt(26, 0);
	for(auto c : ss){
		++ cnt[c - 'a'];
	}
	int shu[2] = {0, 0};
	for(int i = 0; i < 26; ++ i)
		if(cnt[i]) ++ shu[cnt[i] % 2];
	if(k >= shu[1] - 1) cout << "YES\n";
	else cout << "NO\n";
	return ;
}

C. Raspberries

分类讨论
k = 2,3,5 时,只有给定的数变成其的倍数才行,记录改变所需最小值即
k = 4 需特判,k = 4 = 2 * 2,我们

void solve(){
	int n, ans = inf, k, a, shu[2] = {0, 0};
	cin >> n >> k;
	for(int i = 0; i < n; ++ i){
		cin >> a;
		ans = min(ans, (k - a % k) % k);
		++ shu[a % 2];
	}
	if(k == 4){
		if(shu[1] >= 2){
			int t = 2 - min(2, shu[0]);
			ans = min(ans, t);
		}else if(shu[1] == 1){
			if(shu[0] > 1) ans = 0;
			else if(shu[0] == 1) ans = min(ans, 1);
			else ans = min(ans, 3);
		}else{
			if(shu[0] >= 2) ans = 0;
		}
	}
	cout << ans << '\n';
	return ;
}

标签:cnt,shu,905,int,++,Codeforces,ss,ans,div.3
From: https://www.cnblogs.com/Qiansui/p/17782112.html

相关文章

  • Codeforces Round 904 (Div. 2)
    目录写在前面ABCD写在最后写在前面比赛地址:https://codeforces.com/contest/1884捏吗我不会容斥,我是飞舞。A\(k\le10\),于是直接枚举\(x\simx+20\)检查即可。///*By:Luckyblock*/#include<bits/stdc++.h>#defineLLlonglong//=================================......
  • Codeforces Round 855 (Div. 3) C. Powering the Hero
    有\(n\)张卡的卡堆,你可以自顶向下抽卡。装备卡显示数值为\(a_i(a_i>0)\),英雄卡显示数值为\(a_i=0\)。如果是装备卡,你可以将卡抽出放在装备堆。如果是英雄卡,你可以将装备堆顶端的一张数值为\(x\)的装备卡装备给英雄,英雄数值\(+x\)。无论是否装备,都加入英雄堆。询问......
  • Codeforces Round 857 (Div. 2) B. Settlement of Guinea Pigs
    你非常喜欢豚鼠。每个笼子可以住两只豚鼠,且你不想把每个笼子放入不同性别的豚鼠。豚鼠只有两种性别。假设你买到豚鼠时并不知道性别,只有医生能够分辨。接下来的\(n\)天方案中,若第\(i\)天为\(1\),你买入一只豚鼠;若为\(2\),你请医生分辨你的豚鼠性别。给出方案,你最少需要准......
  • Educational Codeforces Round 145 (Rated for Div. 2) B. Points on Plane
    给一个二维平面,你需要在上面放\(n\)个芯片。将一个芯片放在\((x,y)\)的代价为\(|x|+|y|\)。放\(n\)个代价的代价为,所有芯片中耗费的最大代价。并且你需要保证任意两个芯片之间的距离严格\(>1\)。现在给出\(n\)给芯片,询问放\(n\)个芯片的最小代价。一:不难想到......
  • Educational Codeforces Round 149 (Rated for Div. 2)
    这场D被切穿了。A题答案为x或者x-11B题答案就是最长的连续一段的长度+1证明的话大概可以将它看成是几段连续上升和下降的段,然后在峰谷、峰顶分别填上最小、最大,剩下的就依次递增或递减就行。C题将一段连续的0/1视作一个块,那么我们最小化这个块的数量就行。D题如果猜到......
  • Codeforces Round 863 (Div. 3) B. Conveyor Belts
    给一个\(n\timesn\)的矩阵,\(n\)是偶数。将矩阵按圈分割,同一圈的位置可以不消耗代价移动,可以消耗一个代价移动到相邻圈。给出\(n,x_1,y_1,x_2,y_2\),询问\((x_1,y_1)\)移动到\((x_2,y_2)\)的代价最小是多少。显然对每个圈可以选择左上角作为定点。显然直线\(......
  • Codeforces Round 865 (Div. 2) B. Grid Reconstruction
    给一个\(2\timesn\)的网格,且\(n\)是偶数。你需要将\(1\sim2\timesn\)填入这个网格。一条路径是从\((1,1)\)开始,每次只能向右或向下,到\((2,n)\)结束时,所经过的位置。按经过点的顺序标号,一两条路径的代价是\(cost=a_1-a_2+a_3-a_4+\cdots=\sum_{i=1......
  • Codeforces Round 902 (Div. 2, based on COMPFEST 15 - Final Round)
    \(D.EffectsofAntiPimples\)对每个数字能到达的所有位置先预处理最大值,那么就代表选择这个数字之后真实的贡献,那么对这样的预处理值,最小值显然只有一种做法,为\(2^0\),第二小的值应该可以与最小值一起选择,所以答案为\(2^1\),以此类推之后,每个值乘上对应的2的幂次之后求和即......
  • Codeforces Round 872 (Div. 2) B. LuoTianyi and the Table
    给一个\(n\timesm\)的矩阵和\(n\timesm\)个数,你需要把这些数填入矩阵。保证\[\sum_{i=1}^n\sum_{j=1}^m\left(\mathop{max}\limits_{1\leqx\leqi,1\leqy\leqj}a_{x,y}-\mathop{min}\limits_{1\leqx\leqi,1\leqy\leqj}a_{x,y}\right)......
  • Educational Codeforces Round 149 (Rated for Div. 2) C. Best Binary String
    给一个字符串\(s\)包含\(0,1,?\)。定义一个\(01\)串\(s\)的\(cost\)为:选择\(s\)的任意一个子段\([l,r]\)并\(reverse\)。将\(s\)变为一个非降序序列时的\(reverse\)最小次数即\(cost\)。你可以让\(s\)的\(?\)换成\(0/1\),使新\(s\)的\(cost\)......