首页 > 其他分享 >Codeforces Educational Codeforces Round 170 (Rated for Div. 2)

Codeforces Educational Codeforces Round 170 (Rated for Div. 2)

时间:2024-10-15 11:17:27浏览次数:3  
标签:Educational Rated const int Codeforces ++ vector -- define

A - Two Screens

大意:

        给两个字符串,每次在两个空子符串进行两种操作

         1、字符串末尾加一个任意字母

        2、一个字符串全部复制给另一个字符串

        求得到给定的两个字符串的最小操作数

思路:

        看最前面有多少相等即可

        当时想多了。。。

代码:

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10, INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
#define pb push_back
#define  vi vector<int>
#define  vii vector<pair<int, int>>
#define ff first 
#define ss second 
#define rep(i, l, r) for(int i = l; i <= r; i ++)
#define rrep(i, r, l) for(int i = r; i >= l; i --)



void solve()
{
	string s1, s2;
	cin >> s1 >> s2;

	int ans = s1.size() + s2.size();
	int num = min(s1.size(), s2.size());
	if (s1[0] == s2[0])ans++;
	for (int i = 0; i < num; i++)
	{
		if (s1[i] == s2[i])ans--;
		else break;
	}
	cout << ans << endl;

}

signed main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t = 1;
	cin >> t;
	while (t--) solve();

	return 0;
}
/*   /\_/\
*   (= ._.)
*   / >  \>
*/

B - Binomial Coefficients, Kind Of

大意:

        利用错误的公式求组合数

思路:

        首先这个错误的公式没有什么实际意义,找不到简化的公式

        从C\binom{1}{2}开始列举发现了规律,只看上边的数即可,相当于2的i 次方 

        当时组合数还翻了y总算法基础课的四种,发现没有针对这种公式的

代码:

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10, INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
#define pb push_back
#define  vi vector<int>
#define  vii vector<pair<int, int>>
#define ff first 
#define ss second 
#define rep(i, l, r) for(int i = l; i <= r; i ++)
#define rrep(i, r, l) for(int i = r; i >= l; i --)

int qmi(int a, int b)
{
	int res = 1;
	while (b)
	{
		if (b & 1)res = (res * a) % mod;
		a = a * a % mod;
		b /= 2;
	}
	return res;
}

void solve()
{
	int n;
	cin >> n;
	vi v1(n), v2(n);
	for (int i = 0; i < n; i++)cin >> v1[i];
	for (int i = 0; i < n; i++)cin >> v2[i];
	
	for (int i = 0; i < n; i++)
	{
		cout << qmi(2, v2[i]) << endl;
	}
}

signed main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t = 1;
	//cin >> t;
	while (t--) solve();

	return 0;
}
/*   /\_/\
*   (= ._.)
*   / >  \>
*/

C - New Game

大意:

        还是给一堆数,按照相等或加一的拿法,求的是限制拿k种数的情况下,拿的数的最大数量

思路:

        当时就先把这堆不同的数用map记录了一下,然后用vector来存连续的数,然后依次求vector内k段长度的最大值,当时能想到的就这了,化繁为简

代码:

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10, INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
#define pb push_back
#define  vi vector<int>
#define  vii vector<pair<int, int>>
#define ff first 
#define ss second 
#define rep(i, l, r) for(int i = l; i <= r; i ++)
#define rrep(i, r, l) for(int i = r; i >= l; i --)


void solve()
{
	int n, k;cin >> n >> k;
	map<int, int>mp;
	for (int i = 0; i < n; i++)
	{
		int x;cin >> x;
		mp[x] ++;
	}

	int last = -1;

	vector<vi> v(n + 1);
	int idx = -1;
	for (auto i : mp)
	{
		if (last + 1 != i.first)
		{
			v[++idx].push_back(0);
			v[idx].push_back(i.second);
		}
			
		else v[idx].push_back(i.second);
		last = i.first;
	}
	int ans = 0;
	for (auto vv : v)
	{
		if (vv.size() == 0)break;
		int si = vv.size() - 1;
		
		for (int i = 1; i <= si; i++)
		{
			vv[i] += vv[i - 1];
		}
		if (k >= si)
		{
			ans = max(ans, vv[si]);
			continue;
		}
		for (int i = k; i <= si; i++)
		{
			ans = max(ans, vv[i] - vv[i - k]);
		}
	}

	cout << ans << endl;

}

signed main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t = 1;
	cin >> t;
	while (t--) solve();

	return 0;
}
/*   /\_/\
*   (= ._.)
*   / >  \>
*/

D. Attribute Checks

        没做出来,看了jiangly大佬的提交代码https://codeforces.com/contest/2025/submission/285854273

大意:

        给一堆数,如果遇到0,就给正数或负数 +1,如果遇到正数或负数,就比较相应的绝对值,已加的数大于等于该绝对值,ans++,求最大ans

思路:

这个DP的算法当时一直想不明白,之后推演了好几遍才跟上jiangly的思路,

        用了两个vector, DP[j]来存1-n 遍历到第i个数时用掉了j个经验来升级正数的最大通过测试数,f[j]是个中间变量,来记录两个相邻零之间的数对DP的更新值,f[j]表示第j个数结果加了多少

代码:

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10, INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
#define pb push_back
#define  vi vector<int>
#define  vii vector<pair<int, int>>
#define ff first 
#define ss second 
#define rep(i, l, r) for(int i = l; i <= r; i ++)
#define rrep(i, r, l) for(int i = r; i >= l; i --)


void solve()
{
	int n, m;
	cin >> n >> m;

	int num = 0; // 记录当已经分配的经验
	vi dp = { 0 }; // dp[i]记录当前已分配经验下,共i种分配给正数的方案最优解
	vi f = { 0 }; // 记录测试点
	rep(i, 0, n - 1) {
		int r; cin >> r;
		if (r > 0) {	// 正数测试
			if (r < f.size())f[r] ++; // 默认经验点都给正数
		}
		else if (r < 0) {  //负数测试
			r = - r;
			r = num - r; 
			if (r >= 0) { // 如果这个负数测试点有可能通过
				f[0] ++, f[r + 1] --;
			}
		}
		else {
			rep(j, 1, num) f[j] += f[j - 1]; //累加,表示前j种选择的更新量
			rep(j, 0, num) dp[j] += f[j];
			dp.push_back(0);
			num++;
//			cout << "--DP1" << endl;
//			for (auto it : dp)cout << it << "  ";cout << endl;
			rrep(j, num, 1) dp[j] = max(dp[j], dp[j - 1]);
			/*这一步当时想了好久,其实是还是流程没掌握好,
			这一步的DP更新是从大到小更新的,
			因为现在是加了一点经验的时候,所以多加的这一点经验对应的DP直接先取上一个的
			而对于j,DP[j]现在是之前的num + 1个经验点里面选j个,现在比较灵活了
			多出来的经验点给正数,那么DP[j] = DP[j - 1];
			多出来的经验点给负数,那么DP[j] = DP[j];
			而我们只需要取最大值即可
			*/

//			cout << "--DP2" << endl;
//			for (auto it : dp)cout << it << "  ";cout << endl;
			f.assign(num + 1, 0);
		}
	}
	rep(j, 1, num) f[j] += f[j - 1];
	rep(j, 0, num) dp[j] += f[j];
	int ans = *max_element(dp.begin(), dp.end());
	cout << ans << endl;
}

signed main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t = 1;
	//cin >> t;
	while (t--) solve();

	return 0;
}
/*   /\_/\
*   (= ._.)
*   / >  \>
*/

标签:Educational,Rated,const,int,Codeforces,++,vector,--,define
From: https://blog.csdn.net/weixin_47774773/article/details/142938892

相关文章

  • Educational Codeforces Round 170 (Rated for Div. 2)
    目录写在前面A签到B结论C双指针D模拟,差分,DP,结论E计数,DP,F写在最后写在前面比赛地址:https://codeforces.com/contest/2025。妈的不想上学省赛回来昏了一天了。A签到发现最优的操作是先在一个屏幕操作得到最长公共前缀,然后复制到另一方上,再分别操作两方。特判若无公共前......
  • Codeforces Round 978 (Div. 2) A-D1 题解
    我的同学还在VP,排名马上放声明:不要觉得有subtask的题目只做Easyversion没有意义,从这里也能捞很多分,况且有的时候并不是简单和难的区别,而是考不同的算法A.BustoPénjamo题意有一辆车上面有$r$排座位,每排有$2$个座位,现在共$n$个家庭出行坐公交车,每个家庭$a_i$......
  • codeforces round 977 (div.2) C2(访问set的第一个元素,观察数据规律-出现次序,用set记
    解题历程:我首先想到的是等效法,每一次操作可以等效为每次将第一个人抽出放入一组,后面的人往前移,而该组的人就是可以任意放置的人,当b中后面再出现与前一个相同的人时,就不进行操作,当b中出现不同的人时,就看看这组中有没有这个人,有的话就下一个循环,没有的话就看看这个新的人是否按a中......
  • Codeforces Round 899 (Div. 2)题解记录
    题目链接:https://codeforces.com/contest/1882A.IncreasingSequence从1开始慢慢和\(a[i]\)的所有值比较,注意最后一个位置特判下#include<iostream>#include<string.h>#include<map>#include<vector>#include<set>#include<unordered_set>#include<......
  • Splatt3R: Zero-shot Gaussian Splatting from Uncalibrated Image Pairs 论文解读
    目录一、概述二、相关工作1、近期工作2、DUSt3R3、MASt3R三、Splatt3R1、MASt3R的Backbone 2、高斯预测头3、点云与3D高斯参数结合4、3D高斯渲染5、损失函数四、实验 1、对比实验2、消融实验一、概述    该论文首次提出了一种无需任何相机参数和深......
  • FreqFed: A Frequency Analysis-Based Approach for Mitigating Poisoning Attacks in
    FreqFed:AFrequencyAnalysis-BasedApproachforMitigatingPoisoningAttacksinFederatedLearning--FreqFed:一种基于频率分析的联邦学习中缓解中毒攻击的方法来源摘要威胁模型设计目标所用方法FreqFed总结思考来源NetworkandDistributedSystemSecurity......
  • Codeforces Round 946 (Div. 3)
    E.MoneyBuysHappiness题意:给你\(m\)个月,每个月可以赚\(x\)元,每个月你都有一次机会花费\(c_i\)元,获得\(h_i\)的幸福。(当然你目前得有足够的钱)。求出能够获得的最大幸福值。思路:我们可以求出获得\(i\)幸福值所需的最小花费,然后判断能否有足够的钱即可。考虑如何求解,把......
  • [The 3rd Ucup. Stage 10 West Lake] Generated String
    题意维护一个字符串集合,支持动态插入,动态删除,查询同时具有前缀\(s_1\)与后缀\(s_2\)的串的个数,所有字符串用如下方式给出:先给定一个全局模板串\(S\),每一个字符串都是\(S\)的若干个下标区间对应的字符串拼接而成的。即给出若干个区间\([l_1,r_1],[l_2,r_2],\dots,[l_k,r_k......
  • Solution - Codeforces 622E Ants in Leaves
    首先因为\(1\)点是可以一次性到多个点的,因此不需要考虑\(1\)点的情况,而是转而分析\(1\)的每个子树的情况,最后取\(\max\)。那么对于每个子树,就有每个节点每个时刻至多存在\(1\)个点的性质了。考虑如何去求解。首先一个贪心的想法是肯定是每个蚂蚁越早到一个点越好。于......
  • Codeforces Round 932 (Div. 2) C. Messenger in MAC
    对于选定的\(p_i\)的情况下,如何使得代价小?显然是按照\(b\)升序的方式。因此我们可以考虑按照\(b\)进行排序。考虑一种贪心的做法,我们枚举区间\([l,r]\),这样区间的必选就是\(a_l,a_r,(b_r-b_l)\),因此我们可以贪心的选择剩下\(a\)中的最小值。这样复杂度是\(O(n^3\logn)\)。考......