Codeforces Round 888 (Div. 3)(视频讲解全部题目)

news2024/9/22 1:21:22

@[TOC](Codeforces Round 888 (Div. 3)(视频讲解全部题目))

Codeforces Round 888 (Div. 3)(A–G)全部题目详解
在这里插入图片描述

A Escalator Conversations

#include<bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5 + 10;

void solve()
{
	int n, m, k, H;
	cin >> n >> m >> k >> H;
	int ans = 0;
	for(int i = 0; i < n; i ++)
	{
		int h;
		cin >> h;
		int dis = abs(h - H);
		if(h != H && dis % k == 0 && dis / k < m)
			ans ++;
	}
	cout << ans << endl;
}

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

B Parity Sort

#include<bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5 + 10;

void solve()
{
	int n;
	cin >> n;
	vector<int>a(n);
	for(int i = 0; i < n; i ++)
		cin >> a[i];
	vector<int>b;
	b = a;
	sort(b.begin(), b.end());
	for(int i = 0; i < n; i ++)
	{
		if(a[i] % 2 != b[i] % 2)
		{
			cout << "NO" << endl;
			return;
		}
	}
	cout << "YES" << endl;
}

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

C Tiles Comeback

#include<bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5 + 10;

void solve()
{
	int n, k;
	cin >> n >> k;
	vector<int>a(n);
	for(int i = 0; i < n; i ++)
		cin >> a[i];
	if(a[0] == a.back())
	{
		if(count(a.begin(), a.end(), a[0]) >= k)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	else
	{
		int c1 = count(a.begin(), a.end(), a[0]);
		int c2 = count(a.begin(), a.end(), a.back());
		int cnt = 0;
		for(int i = 0; i < n; i ++)
		{
			if(a[i] == a[0])
				cnt ++;
			if(a[i] == a.back())
				c2 --;
			if(cnt == k)
				break;
		}
		if(c1 >= k && c2 >= k)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}

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

D Prefix Permutation Sums

#include<bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5 + 10;

void solve()
{
	int n;
	cin >> n;
	vector<int>a(n - 1);
	for(int i = 0; i < n - 1; i ++)
		cin >> a[i];
	int sum = n * (n + 1) / 2;
	if(sum != a.back())
	{
		a.push_back(sum);

		map<int,bool>st;

		for(int i = 0; i < n; i ++)
		{
			int b;
			if(!i)
				b = a[i];
			else
				b = a[i] - a[i - 1];
			if(b <= 0 || b > n || st[b])
			{
				cout << "NO" << endl;
				return;
			}
			st[b] = true;
		}
		cout << "YES" << endl;
	}
	else
	{
		map<int,bool>st;
		int x, cnt = 0;
		for(int i = 0; i < n - 1; i ++)
		{
			int b;
			if(!i)
				b = a[i];
			else
				b = a[i] - a[i - 1];
			if(b <= 0 || b > 2 * n)
			{
				cout << "NO" << endl;
				return;
			}
			if(b > n || st[b])
			{
				x = b;
				cnt ++;
			}
			st[b] = true;
		}
		if(cnt > 1)
		{
			cout << "NO" << endl;
			return;
		}
		else
		{
			int sum = 0;
			int c = 0;
			for(int i = 1; i <= n; i ++)
			{
				if(!st[i])
				{
					sum += i;
					c ++;
				}
			}
			if(c == 2 && sum == x)
			{
				cout << "YES" << endl;
			}
			else
			{
				cout << "NO" << endl;
			}
		}
	}
}

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

E Nastya and Potions

#include<bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 2e5 + 10;
int c[N], idx[N], ans[N];
map<int,bool>p;
int n, k;
vector<int>edge[N];

void bfs()
{
	queue<int>q;
	for(int i = 0; i < n; i ++)
	{
		if(idx[i] == 0)
		{
			q.push(i);
			if(p[i])
				ans[i] = 0;
			else
				ans[i] = c[i];
		}
	}

	while(q.size())
	{
		int t = q.front();
		q.pop();
		for(int i = 0; i < edge[t].size(); i ++)
		{
			int son = edge[t][i];
			ans[son] += ans[t];
			idx[son] --;
			if(idx[son] == 0)
			{
				if(p[son])
					ans[son] = 0;
				else
					ans[son] = min(ans[son], c[son]);
				q.push(son);
			}
		}

	}
}

void solve()
{

	cin >> n >> k;
	for(int i = 0; i < n; i ++)
	{
		c[i] = idx[i] = ans[i] = 0;
		edge[i].clear();
	}
	p.clear();
	for(int i = 0; i < n; i ++)
		cin >> c[i];
	for(int i = 0; i < k; i ++)
	{
		int x;
		cin >> x;
		x --;
		p[x] = true;
	}
	for(int i = 0; i < n; i ++)
	{
		int m;
		cin >> m;
		for(int j = 0; j < m; j ++)
		{
			int x;
			cin >> x;
			x --;
			idx[i] ++;
			edge[x].push_back(i);
		}
	}
	bfs();
	for(int i = 0; i < n; i ++)
		cout << ans[i] << " ";
	cout << endl;
}

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

F Lisa and the Martians

#include<bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5 + 10;

void solve()
{
	int n, k;
	cin >> n >> k;
	vector<pii>a(n);

	for(int i = 0; i < n; i ++)
	{
		cin >> a[i].first;
		a[i].second = i + 1;
	}
	sort(a.begin(), a.end());
	int minv = INT_MAX, a1, a2, p1, p2;
	for(int i = 0; i < n - 1; i ++)
	{
		if(minv > (a[i].first ^ a[i + 1].first))
		{
			a1 = a[i].first, a2 = a[i + 1].first;
			p1 = a[i].second, p2 = a[i + 1].second;
			minv = a1 ^ a2;
		}
	}
	int x = 0;
	for(int i = 0; i < k; i ++)
	{
		int x1 = (a1 >> i) & 1, x2 = (a2 >> i) & 1;
		if(x1 + x2 == 0)
			x += 1 << i;
	}
	cout << p1 << " " << p2 << " " << x << endl;
}

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

G Vlad and the Mountains

#include<bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 2e5 + 10;
int h[N], p[N];
struct NODE
{
	int a, b, w;
};
struct QRY
{
	int a, b, h_max, ii;
};
vector<NODE>edge;
vector<QRY>Q;
bool cmp1(NODE x, NODE y)
{
	return x.w < y.w;
}
bool cmp2(QRY x, QRY y)
{
	return x.h_max < y.h_max;
}

int find(int x)
{
	if(x != p[x])
		p[x] = find(p[x]);
	return p[x];
}
void solve()
{
	edge.clear();
	Q.clear();
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= n; i ++)
		cin >> h[i];
	for(int i = 0; i < m; i ++)
	{
		int a, b;
		cin >> a >> b;
		edge.push_back({a,b, max(h[a], h[b])});
	}
	sort(edge.begin(), edge.end(), cmp1);
	int q;
	cin >> q;
	vector<bool>ans(q);
	for(int i = 0; i <= n; i ++)
		p[i] = i;

	for(int i = 0; i < q; i ++)
	{
		int a, b, e;
		cin >> a >> b >> e;
		Q.push_back({a, b, h[a] + e, i});
	}
	sort(Q.begin(), Q.end(), cmp2);
	int cnt = 0;
	for(int i = 0; i < q; i ++)
	{
		while(cnt < m && Q[i].h_max >= edge[cnt].w)
		{
			int pa = find(edge[cnt].a), pb = find(edge[cnt].b);
			if(pa != pb)
				p[pa] = pb;
			cnt ++;
		}
		if(find(Q[i].a) == find(Q[i].b))
			ans[Q[i].ii] = true;
		else
			ans[Q[i].ii] = false;
	}
	for(int i = 0; i < q; i ++)
	{
		if(ans[i])
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	cout << endl;
}

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/802202.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

数据结构:顺序表(C实现)

个人主页 水月梦镜花 个人专栏 C语言 &#xff0c;数据结构 文章目录 一、顺序表二、实现思路1.存储结构2.初始化顺序表(SeqListInit)3.销毁顺序表(SeqListDestroty)4.打印顺序表(SeqListPrint)5.顺序表尾插(SeqListPushBack)and检查容量(SeqListCheckCapacity)6.顺序表头插(Se…

大数据面试题之Elasticsearch:每日三题(六)

大数据面试题之Elasticsearch:每日三题 1. 为什么要使用Elasticsearch&#xff1f;2.Elasticsearch的master选举流程&#xff1f;3.Elasticsearch集群脑裂问题&#xff1f; 1. 为什么要使用Elasticsearch&#xff1f; 系统中的数据&#xff0c;随着业务的发展&#xff0c;时间…

如何创建一个容器并运行docker镜像

文章目录 如何创建一个容器并使用docker镜像docker命令解析nacos启动成功 访问 进入容器&#xff0c;修改配置文件 接上集 CentOS 7安装Docker https://blog.csdn.net/qq_39017153/article/details/131955100 如何创建一个容器并使用docker镜像 还是打开镜像容器官网https://hu…

JS如何获取最近一个月或指定天数的日期,并以数组的形式存储

JS如何获取最近一个月或指定天数的日期,并以数组的形式存储 代码 num为传递的天数 (传递30查最近一个月) get_date(num) {let dateArray []//获取今天日期let myDate new Date()let today myDate.getFullYear() - (myDate.getMonth() 1) "-" myDate.getDate(…

升讯威在线客服系统是如何实现对 IE8 完全完美支持的(怎样从 WebSocket 降级到 Http)【干货】

简介 升讯威在线客服与营销系统是基于 .net core / WPF 开发的一款在线客服软件&#xff0c;宗旨是&#xff1a; 开放、开源、共享。努力打造 .net 社区的一款优秀开源产品。 完整私有化包下载地址 &#x1f4be; https://kf.shengxunwei.com/freesite.zip 当前版本信息 发布…

【unity之IMGUI实践】敌方逻辑封装实现【六】

&#x1f468;‍&#x1f4bb;个人主页&#xff1a;元宇宙-秩沅 &#x1f468;‍&#x1f4bb; hallo 欢迎 点赞&#x1f44d; 收藏⭐ 留言&#x1f4dd; 加关注✅! &#x1f468;‍&#x1f4bb; 本文由 秩沅 原创 &#x1f468;‍&#x1f4bb; 收录于专栏&#xff1a;uni…

技术实力加速企业上云,联想混合云获评专有云优秀案例入选混合云全景图四大方向

7月25-26日&#xff0c;由中国信息通信研究院、中国通信标准化协会联合主办的第十届可信云大会在京顺利召开。大会重磅发布了云计算白皮书&#xff08;2023年&#xff09;、《混合云产业全景图&#xff08;2023&#xff09;》、中国算力服务研究报告、中国云计算发展指数报告等…

Stream流之distinct去重详细用法

前言 distinct方法在Stream流中可以进行集合中的去重操作&#xff0c;但是要按照集合中的数据类型具体来定义。简单数据类型和自定义数据类型操作不同。 简单数据类型 这里以List集合为例&#xff0c;并且集合中数据类型为Integer。简单数据类型直接调用Stream中的distinct方…

抖音短视频seo源码矩阵系统开发

一、前言&#xff1a; 抖音SEO源码矩阵系统开发是一项专为抖音平台设计的SEO优化系统&#xff0c;能够帮助用户提升抖音视频的搜索排名和曝光度。为了确保系统运行正常&#xff0c;需要安装FFmpeg和FFprobe工具。FFmpeg是一个用于处理多媒体数据的开源工具集&#xff0c;而FFpr…

【密码学】三、分组密码的工作模式

分组密码的工作模式 ECB模式CBC模式CFB模式OFB模式CTR模式 电子密码本ECB、密码分组链接模式CBC、密码反馈模式CFB和输出反馈模式OFB、计数器模式CTR ECB模式 它一次对一个64bit长的明文分组加密&#xff0c;而且每次的加密密钥都相同。可以认为有一个非常大的电子密码本&…

在数字化时代,数字孪生能挽回中医的地位嘛?

中医作为中国传统医学的瑰宝&#xff0c;拥有悠久的历史和深厚的文化底蕴。然而&#xff0c;随着现代医学的快速发展&#xff0c;中医面临着许多挑战和困境。在这个数字化时代&#xff0c;数字孪生作为一项前沿技术&#xff0c;是否能为中医行业带来新的希望和机遇呢&#xff1…

制定机器学习规划路线:从入门到专业

文章目录 &#x1f340;第一阶段&#xff1a;入门基础&#x1f340;了解机器学习概念&#x1f340;学习编程和数学基础&#x1f340;探索经典机器学习算法&#x1f340;完成实践项目 &#x1f340;第二阶段&#xff1a;深入学习&#x1f340; 掌握深度学习基础&#x1f340;学习…

无法定位程序输入点:于动态链接库KERNEL32.dll上(未解决)

错误如图&#xff1a; 搜索了一下&#xff0c;说是下载KERNEL32.dll。我在WINDOWS目录下搜索了&#xff0c;实际上这个文件已经存在&#xff1a; 原因猜测&#xff0c;应该是软件本身与系统版本不配套导致的。可能是.NET&#xff1f;C

JAVA课程期末复习学习总结

JAVA课程学习总结 知识点总结 文章目录 JAVA课程学习总结知识点总结Eclipse如何与GitHub连接1.前期准备2.远程建库3.本地操作 常用DOS命令数组正则表达式继承多态向上转型向下转型多态的应用抽象方法 抽象类与接口的异同点不同点&#xff1a;相同点&#xff1a;从设计理念层面…

【MySQL】事务与隔离级别详解

【MySQL】事务 事务的概念为什么要有事务引擎对事务的支持事务的提交方式事务的操作准备正常事务操作&#xff1a;启动、回滚、提交非正常事务总结 事务的隔离级别隔离性隔离级别隔离级别的查看设置隔离级别会话级别全局级别 隔离级别的具体体现读未提交 Read Uncommitted读提交…

本土机器视觉创业企业涌现,深眸科技携手AI+3D视觉勇闯小场景赛道

随着工业自动化技术向智能化方向发展&#xff0c;人工智能实现快速落地&#xff0c;机器视觉应用产品在算力、算法和技术等方面得到持续升级&#xff0c;助力中国机器视觉行业进入高质量发展阶段。 在制造业转型升级、新兴产业发展的过程中&#xff0c;中国作为全球制造中心之…

第十四章:通过迭代挖掘共同物体特征的弱监督语义分割

0.摘要 在图像标签监督下进行弱监督语义分割是一项具有挑战性的任务&#xff0c;因为它直接将高层语义与低层外观相关联。为了弥合这一差距&#xff0c;本文提出了一种迭代的自底向上和自顶向下的框架&#xff0c;交替扩展对象区域和优化分割网络。我们从分类网络产生的初始定位…

新版mmpose训练新版RTMDet/Pose及自定义数据集制作

自定义数据集制作:要求满足目标检测网络和关键点检测网络都可以用其来训练 1. 打开Labelme并导入我们的图像文件夹;2. 用矩形框框出目标检测网络要检测的目标,我们起名叫person;3. 用Creat Point 标记关键点,这里我们只检测人的头和裆两个点。这里教一个小技巧:每一个数据…

Mindar.JS——实现AR图像追踪插入图片或视频

Mindar.JS使用方式 注意&#xff1a;此篇文章需要启动https才可调用相机权限 图像追踪示例 需要用到两个js库 <script src"./js/aframe.min.js"></script><script src"./js/mindar-image-aframe.prod.js"></script>下面看一下标签…

一款性价比高的知识管理系统应具备的功能

编者按&#xff1a;市面上的知识管理系统有不同的类型&#xff0c;有针对文件管理的&#xff0c;也有针对内容管理的&#xff0c;各有长处&#xff0c;那么一款好用的KMS大概都具备哪些优点呢&#xff1f; 关键词&#xff1a;知识管理系统、免运维/安装、 随着企业对企业隐形知…