Educational Codeforces Round 157 (A--D)视频详解

Educational Codeforces Round 157 (A--D)视频详解

视频链接

Educational Codeforces Round 157 (A--D)视频详解

A题代码

cpp 复制代码
#include<bits/stdc++.h>
#define endl '\n'
#define deb(x) cout << #x << " = " << x << '\n';
#define INF 0x3f3f3f3f
using namespace std;
int x, y, k;

void solve()
{
	cin >> x >> y >> k;
	if(x >= y)
	{
		cout << x << endl;
		return;
	}
	else
	{
		cout << y + (max(y - x - k, 0)) << endl;
		return;
	}

}

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

B题代码

cpp 复制代码
#include<bits/stdc++.h>
#define endl '\n'
#define deb(x) cout << #x << " = " << x << '\n';
#define INF 0x3f3f3f3f
using namespace std;

void solve()
{
	int n;
	cin >> n;
	vector<int>a(2 * n);
	for(int i = 0; i < 2 * n; i ++)
		cin >> a[i];
	
	sort(a.begin(), a.end());

	cout << abs(a[n - 1] - a[0]) + abs(a[2 * n - 1] - a[n]) << endl;

	for(int i = 0; i < n; i ++)
		cout << a[i] << " " << a[n + i] << endl;

}

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

C题代码

cpp 复制代码
#include<bits/stdc++.h>
#define endl '\n'
#define deb(x) cout << #x << " = " << x << '\n';
#define INF 0x3f3f3f3f
#define int long long
using namespace std;

map<int,map<int,int>>cnt;

int GetInt(string s)
{
	int res = 0;
	for(int i = 0; i < s.size(); i ++)
		res += s[i] - '0';

	return res;
}

void solve()
{
	int n;
	cin >> n;
	vector<string>s(n);
	for(int i = 0; i < n; i ++)
	{
		cin >> s[i];
		cnt[GetInt(s[i])][s[i].size()] ++;
	}

	int ans = 0;
	for(int i = 0; i < n; i ++)
	{
		for(int j = 0; j < s[i].size(); j ++)
		{
			string str1 = s[i].substr(0, j + 1);
			string str2 = s[i].substr(j + 1);

			int s1 = GetInt(str1);
			int a1 = GetInt(str2);
			ans += cnt[s1 - a1][str1.size() - str2.size()];
			
			int s2 = GetInt(str2);
			int a2 = GetInt(str1);
			ans += cnt[s2 - a2][str2.size() - str1.size()];
		}
	}
	
	cout << ans << endl;
}

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

D题代码

cpp 复制代码
#include<bits/stdc++.h>
#define endl '\n'
#define deb(x) cout << #x << " = " << x << '\n';
#define INF 0x3f3f3f3f
using namespace std;
const int N = 2e5 + 10;
int a[N], c[N];
int son[N * 31][2], idx;
int n;

void insert(int x)
{
	int p = 0;
	for(int i = 30; i >= 0; i -- )
	{
		int t = x >> i & 1;
		if(!son[p][t])son[p][t] = ++ idx;
		p = son[p][t];
	}
}

int query(int x)
{
	int p = 0, res = 0;
	for(int i = 30; i >= 0; i --)
	{
		int t = x >> i & 1;
		if(son[p][!t])
			res = (res << 1) + !t, p = son[p][!t];
		else
			res = (res << 1) + t, p = son[p][t];
	}
	return res;
}

void solve()
{
	cin >> n;
	for(int i = 1; i <= n - 1; i ++)
	{
		cin >> a[i], c[i] = c[i - 1] ^ a[i];
		insert(c[i]);
	}

	int b = INF;
	for(int i = 0; i < n; i ++)
	{
		if((query(i) ^ i) <= n - 1)
		{
			//deb((query(i) ^ i));
			b = i;
			break;
		}
	}

	cout << b << " ";
	for(int i = 1; i <= n - 1; i ++)
	{
		cout << (b ^ c[i]) << " ";
	}
	cout << endl;
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	t = 1;
	//cin >> t;
	while(t--)
	solve();
}
相关推荐
吃着火锅x唱着歌1 天前
LeetCode 1128.等价多米诺骨牌对的数量
算法·leetcode·职场和发展
十八岁讨厌编程1 天前
【算法训练营 · 补充】LeetCode Hot100(中)
算法·leetcode
橘颂TA1 天前
【剑斩OFFER】算法的暴力美学——最小覆盖字串
算法·c/c++·就业
wearegogog1231 天前
基于混合蛙跳算法和漏桶算法的无线传感器网络拥塞控制与分簇新方法
网络·算法
程序员龙一1 天前
C++之static_cast关键字
开发语言·c++·static_cast
奶茶树1 天前
【C++/STL】map和multimap的使用
开发语言·c++·stl
Tiandaren1 天前
大模型应用03 || 函数调用 Function Calling || 概念、思想、流程
人工智能·算法·microsoft·数据分析
2301_795167201 天前
玩转Rust高级应用 如何进行理解Refutability(可反驳性): 模式是否会匹配失效
开发语言·算法·rust
云知谷1 天前
【C/C++基本功】C/C++江湖风云录:void* 的江湖传说
c语言·开发语言·c++·软件工程·团队开发
小当家.1051 天前
[LeetCode]Hot100系列.贪心总结+思想总结
算法·leetcode·职场和发展