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();
}
相关推荐
顾子茵8 分钟前
c++从入门到精通(五)--异常处理,命名空间,多继承与虚继承
开发语言·c++
冲帕Chompa39 分钟前
图论part10 bellman_ford算法
数据结构·算法·图论
緈福的街口42 分钟前
【leetcode】144. 二叉树的前序遍历
算法·leetcode
GG不是gg1 小时前
排序算法之基础排序:冒泡,选择,插入排序详解
数据结构·算法·青少年编程·排序算法
随意起个昵称1 小时前
【双指针】供暖器
算法
倒霉蛋小马1 小时前
最小二乘法拟合直线,用线性回归法、梯度下降法实现
算法·最小二乘法·直线
YueiL1 小时前
基于RK3588的智慧农场系统开发|RS485总线|华为云IOT|node-red|MQTT
c++·物联网·华为云·rk3588·rs485
二进制人工智能1 小时前
【OpenGL学习】(二)OpenGL渲染简单图形
c++·opengl
codists2 小时前
《算法导论(第4版)》阅读笔记:p82-p82
算法
埃菲尔铁塔_CV算法2 小时前
深度学习驱动下的目标检测技术:原理、算法与应用创新
深度学习·算法·目标检测