5.30 学习总

news2024/10/6 1:53:04

刷题记录(Codeforces Round 947 (Div. 1 + Div. 2)B,C题)和Codeforces Round 948 (Div. 2)B题

一.B. 378QAQ and Mocha's Array
B. 378QAQ and Mocha's Array
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Mocha likes arrays, so before her departure, 378QAQ gave her an array a𝑎 consisting of n𝑛 positive integers as a gift.

Mocha thinks that a𝑎 is beautiful if there exist two numbers i𝑖 and j𝑗 (1≤i,j≤n1≤𝑖,𝑗≤𝑛i≠j𝑖≠𝑗) such that for all k𝑘 (1≤k≤n1≤𝑘≤𝑛), ak𝑎𝑘 is divisible†† by either ai𝑎𝑖 or aj𝑎𝑗.

Determine whether a𝑎 is beautiful.

†† x𝑥 is divisible by y𝑦 if there exists an integer z𝑧 such that x=y⋅z𝑥=𝑦⋅𝑧.

Input

Each test contains multiple test cases. The first line contains the number of test cases t𝑡 (1≤t≤5001≤𝑡≤500). The description of the test cases follows.

The first line of each test case contains a single integer n𝑛 (3≤n≤1053≤𝑛≤105) — the length of the array a𝑎.

The second line of each test case contains n𝑛 integers a1,a2,…,an𝑎1,𝑎2,…,𝑎𝑛 (1≤ai≤1091≤𝑎𝑖≤109) — the elements of the array a𝑎.

It is guaranteed that the sum of n𝑛 over all test cases does not exceed 105105.

Output

For each test case, output "Yes" if array a𝑎 is beautiful, and output "No" otherwise.

You can output "Yes" and "No" in any case (for example, strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive response).

Example
input
Copy
 
        
4
3
7 3 8
5
7 1 9 3 5
5
4 12 2 6 3
5
7 49 9 3 1000000000
output
Copy
No
Yes
Yes
No
Note

In the first test case, any two numbers in the array are coprime, so the answer is "No".

In the second test case, we can pick i=2𝑖=2 and j=1𝑗=1. Since every number in the array is divisible by ai=1𝑎𝑖=1, the answer is "Yes".

In the third test case, we can pick i=3𝑖=3 and j=5𝑗=522 and 44 is divisible by ai=2𝑎𝑖=2 while 3366 and 1212 is divisible by aj=3𝑎𝑗=3, so the answer is "Yes".

题意:题目要求我们找到两个数,使得整个数组的每个数都可以被两个数至少一个整除。

思路:因为是整除关系,小数一定不能被大数整除,所以从最小数下手。

找到的第一个数一定是数组的最小数,第二个数为能被第一个数整除的最小数。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
void solve()
{
	ll n;
	cin>>n;
	vector<ll>a(n);
	for(ll &i:a)
	{
		cin>>i;
	}
	if(n<=2)
	{
		cout<<"Yes\n";
		return;
	}
	bool ans=true;
	sort(a.begin(),a.end());
	ll b,c;
	b=a[0];
	int f=0,f1=0;
	for(int i=1;i<n;i++){
		if(a[i]!=a[i-1]) 
		{
			f=1;
		}
		if(a[i]%b!=0&&f==1)
		{
			f1=1;
			c=a[i];
			break;
		}
	}
	if(f==0||f1==0)
	{
		cout<<"Yes\n";
		return ;
	}
	for(ll i=2;i<n;i++){
		if(a[i]%b!=0&&a[i]%c!=0) 
		{
			ans=false;
			break;
		}
	}
	cout<<(ans?"Yes\n":"No\n");
}
int main()
{
	int t;
	cin>>t;
	
	while(t--){
		solve();
	}
	return 0;
}

二.C. Chamo and Mocha's Array

C. Chamo and Mocha's Array
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Mocha likes arrays, so before her departure, Chamo gave her an array a𝑎 consisting of n𝑛 positive integers as a gift.

Mocha doesn't like arrays containing different numbers, so Mocha decides to use magic to change the array. Mocha can perform the following three-step operation some (possibly, zero) times:

  1. Choose indices l𝑙 and r𝑟 (1≤l<r≤n1≤𝑙<𝑟≤𝑛)
  2. Let x𝑥 be the median†† of the subarray [al,al+1,…,ar][𝑎𝑙,𝑎𝑙+1,…,𝑎𝑟]
  3. Set all values al,al+1,…,ar𝑎𝑙,𝑎𝑙+1,…,𝑎𝑟 to x𝑥

Suppose a=[1,2,3,4,5]𝑎=[1,2,3,4,5] initially:

  • If Mocha chooses (l,r)=(3,4)(𝑙,𝑟)=(3,4) in the first operation, then x=3𝑥=3, the array will be changed into a=[1,2,3,3,5]𝑎=[1,2,3,3,5].
  • If Mocha chooses (l,r)=(1,3)(𝑙,𝑟)=(1,3) in the first operation, then x=2𝑥=2, the array will be changed into a=[2,2,2,4,5]𝑎=[2,2,2,4,5].

Mocha will perform the operation until the array contains only the same number. Mocha wants to know what is the maximum possible value of this number.

†† The median in an array b𝑏 of length m𝑚 is an element that occupies position number ⌊m+12⌋⌊𝑚+12⌋ after we sort the elements in non-decreasing order. For example, the median of [3,1,4,1,5][3,1,4,1,5] is 33 and the median of [5,25,20,24][5,25,20,24] is 2020.

Input

Each test contains multiple test cases. The first line contains the number of test cases t𝑡 (1≤t≤5001≤𝑡≤500). The description of the test cases follows.

The first line of each test case contains a single integer n𝑛 (2≤n≤1052≤𝑛≤105) — the length of the array a𝑎.

The second line of each test case contains n𝑛 integers a1,a2,…,an𝑎1,𝑎2,…,𝑎𝑛 (1≤ai≤1091≤𝑎𝑖≤109) — the elements of the array a𝑎.

It is guaranteed that the sum of n𝑛 over all test cases does not exceed 105105.

Output

For each test case, output the maximum value of the number.

Example
input
Copy
 
        
2
2
1 2
5
1 2 3 4 5
output
Copy
1
4
Note

In the first test case, a=[1,2]𝑎=[1,2]. Mocha can only choose the interval (l,r)=(1,2)(𝑙,𝑟)=(1,2). The array will be changed to a=[1,1]𝑎=[1,1]. Therefore, the answer is 11.

In the second test case, Mocha can perform the following operations:

  • Choose the interval (l,r)=(4,5)(𝑙,𝑟)=(4,5), then a=[1,2,3,4,4]𝑎=[1,2,3,4,4].
  • Choose the interval (l,r)=(3,5)(𝑙,𝑟)=(3,5), then a=[1,2,4,4,4]𝑎=[1,2,4,4,4].
  • Choose the interval (l,r)=(1,5)(𝑙,𝑟)=(1,5), then a=[4,4,4,4,4]𝑎=[4,4,4,4,4].

The array contains only the same number, which is 44. It can be proven that the maximum value of the final number cannot be greater than 44.

题意:对于整个数组,我们可以选择一个范围(l,r),将这个范围内的数全部变为这个范围内的中位数,可以进行多次操作或者不做操作,求最后的数组的全部元素的最大值。

思路:因为当选择的范围长度是2时,就可以将这个范围的两个数全部变为这两个数的较小值(x),那么一定存在一个长度为3的范围内的中位数<=x。

如果整个数组的长度为2,输出较小值即可,反之,遍历数组全部长度为3的子数组,找到最大的中位数,然后输出。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
void solve()
{
	int n;
	cin>>n;
	vector<int>a(n);
	for(int &i:a)
	cin>>i;
	if(n==2)
	{
		cout<<min(a[0],a[1])<<"\n";
		return;	
	}
	ll ans=-1;
	for(int i=0;i<n-2;i++){
		int p[3];
		p[0]=a[i];
		p[1]=a[i+1];
		p[2]=a[i+2];
		sort(p,p+3);
		ans=max(ans,(ll)p[1]);
	}
	cout<<ans<<"\n";
}
int main()
{
	int t;
	cin>>t;
	while(t--){
		solve();
		
	}
	return 0;
}

三.B. Symmetric Encoding

B. 对称编码
每次测试的时间限制
为 2 秒
每次测试的内存限制
256 兆字节
输入
标准输入
输出
标准输出

Polycarp 有一根绳子s𝑠,由小写的拉丁字母组成。他使用以下算法对此字符串进行编码:

  • 首先,他构造了一个新的辅助弦r𝑟,它由字符串的所有不同字母组成s𝑠,按字母顺序书写;
  • 然后编码如下:字符串中的每个字符s𝑠替换为字符串中的对称字符r𝑟(字符串的第一个字符r𝑟将被最后一个替换,第二个被倒数第二个替换,依此类推)。

例如,对字符串进行编码s𝑠="CodeForces“的发生方式如下:

  • 字符串r𝑟以“cdefors";
  • 第一个字符s1𝑠1='c' 替换为 的';
  • 第二个角色s2𝑠2='o' 替换为 'e';
  • 第三个角色s3𝑠3='d' 替换为 'r';
  • ...
  • 最后一个字符s10𝑠10='s“替换为”c“。

字符串r𝑟和替代品s𝑠="CodeForces“。

因此,对字符串进行编码的结果s𝑠="codeforces“是字符串”serofedsoc“。

编写一个执行解码的程序,即恢复原始字符串s𝑠从编码结果。

输入

第一行包含单个整数t𝑡 (1≤吨≤1041≤𝑡≤104) — 测试用例的数量。

每个测试用例的第一行包含一个整数n𝑛 (1≤N≤2⋅1051≤𝑛≤2⋅105) — 字符串的长度b𝑏.

每个测试用例的第二行都包含一个字符串b𝑏长度n𝑛,由小写拉丁字母组成 — 对原始字符串进行编码的结果s𝑠.

可以保证n𝑛在测试中的所有测试用例不超过2⋅1052⋅105.

输出

对于每个测试用例,输出字符串s𝑠从中获取编码结果b𝑏已获得。

输入
复制
 
        
5
10
serofedsoc
3
ttf
9
tlrhgmaoi
1
w
15
hnndledmnhlttin
输出
复制
codeforces
fft
algorithm
w
meetinthemiddle

#include<bits/stdc++.h>
using namespace std;
void solve()
{
	int n;
	cin>>n;
	string s,t,v;
	cin>>s;
	t=s;
	sort(t.begin(),t.end());
	
	for(int i=0;i<n;i++){
		if(t[i]!=t[i+1]) v+=t[i];
	}
	map<char,char>q;
	for(int i=0;i<v.size();i++){
		q[v[i]]=v[v.size()-1-i];
	}
	for(int i=0;i<n;i++){
		
		s[i]=q[s[i]];
	}
	cout<<s<<"\n";
}
int main()
{
	int t;
	cin>>t;
	while(t--){
		solve();
	}
}

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

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

相关文章

Android 11 Audio strategy配置解析

在启动AudioPolicyService时&#xff0c;通过EngineBase的loadAudioPolicyEngineConfig函数去解析strategy配置。其调用流程如下 接下来就对loadAudioPolicyEngineConfig展开分析 1&#xff0c;解析volume标签 engineConfig::ParsingResult EngineBase::loadAudioPolicyEngine…

构建 VPC 并启动 Web 服务器

实验 2&#xff1a;构建 VPC 并启动 Web 服务器 目标 完成本实验后&#xff0c;您可以&#xff1a; 创建 VPC。创建子网。配置安全组。在 VPC 中启动 EC2 实例。任务 1&#xff1a;创建 VPC 在本任务中&#xff0c;您将使用 VPC 向导在单个可用区中创建一个 VPC、一个互联网网关…

【vueCms】vueCms后台管理系统安装问题集合

开源项目地址: https://www.vuecms.cn/ 开源代码地址: https://gitee.com/derekgo/vue-cms_xg 问题一 如果出现提示少了个index.html。如下图 解决办法: 重新安装前端(vue3_vite)项目依赖 问题二 npm版本高无法解析依赖树导致依赖下载失败 解决方案: npm install --legacy…

Web程序设计-实验05 DOM与BOM编程

题目 【实验主题】 影视网站后台影视记录管理页设计 【实验任务】 1、浏览并分析多个网站后台的列表页面、编辑页面&#xff08;详见参考资源&#xff0c;建议自行搜索更多后台页面&#xff09;的主要元素构成和版面设计&#xff0c;借鉴并构思预期效果。 2、新建 index.h…

ODBC访问达梦数据库Ubuntu18.04 x86-x64(亲测有效)

ODBC访问达梦数据库Ubuntu18.04 x86-x64 第1步&#xff1a;安装unixodbc驱动,使用下面命令。第2步&#xff1a;拷贝已经安装好的达梦数据库驱动程序第3步&#xff1a;配置ODBC必要的参数文件&#xff0c;如下图第4步&#xff1a;设置环境变量第5步&#xff1a;连接测试 说明&am…

Linux实验六:进程间通信(二)

目录 一、实验目的二、实验内容三、实验环境四、参考代码五、实验步骤步骤1. 编辑源代码test6.c步骤2. 编译源代码test6.c步骤3. 运行可执行程序test6步骤4. 进一步调试源代码test6.c 六、实验结果七、实验总结 一、实验目的 1、理解 POSIX 和 System V 提供的 IPC 相关概念&a…

Unity 自定义房间布局系统 设计与实现一个灵活的房间放置系统 ——自定义房间区域功能

自定义房间区域功能 效果&#xff1a; 功能&#xff1a; 能够自定义房间的大小一键生成放置区域可控的放置网格点当物体放置到区域内可自动吸附物体是否可放置&#xff0c;放置时如果与其他物体交叉则不可放置&#xff08;纯算法计算&#xff09;管理房间内的物体&#xff0c…

【实战JVM】-实战篇-05-内存泄漏及分析

【实战JVM】-实战篇-05-内存泄漏及分析 1 内存溢出和内存泄漏1.1 常见场景1.2 解决内存溢出的方法1.2.1 发现问题1.2.1.1 top1.2.1.2 ViusalVM1.2.1.3 arthas1.2.1.4 PrometheusGrafana 1.2.2 堆内存状况对比1.2.3 内存泄漏原因-代码中1.2.3.1 equals()-hashCode()1.2.3.2 内部…

相机等效焦距

1. 背景 物理焦距我们很熟悉,但是在接触实际的相机参数时,相机厂家会提到一个参数等效焦距,甚至有时候不提供物理焦距,这时候如果我们得到真实的物理焦距需要进行一定的转换.在介绍两者之间的转换关系前,先介绍一下等效焦距的由来. 如上图,假设在某一个镜头,其成像面会出现图…

Linux配置java,maven,marshalsec环境

文章目录 一. Linux配置java环境1.下载jdk文件2.解压tar.gz文件3.设置java环境变量4.验证是否成功 二. Linux配置maven环境1.下载压缩包2.解压tar.gz3. 配置环境变量 三. Linux配置marshalsec环境 一. Linux配置java环境 1.下载jdk文件 mkdir /opt/javawget https://repo.hua…

【设计模式深度剖析】【5】【结构型】【桥接模式】| 以电视和遥控器为例加深理解

&#x1f448;️上一篇:组合模式 | 下一篇:外观模式&#x1f449;️ 设计模式-专栏&#x1f448;️ 目 录 桥接模式(Bridge Pattern)定义英文原话是&#xff1a;直译理解 4个角色UML类图代码示例 应用优点缺点使用场景 示例解析&#xff1a;电视和遥控器UML类图 桥接模式…

【漏洞复现】DT-高清车牌识别摄像机 任意文件读取漏洞

0x01 产品简介 DT-高清 车牌识别摄像机是一款先进的安防设备&#xff0c;采用高清图像传感器和先进的识别算法&#xff0c;能够精准、快速地识别车牌信息。其高清晰该摄像机结合了智能识别技术&#xff0c;支持实时监宴图像质量确保在各种光照和天气条件下都能准确捕捉车牌信息…

【设计模式】JAVA Design Patterns——Factory Method(虚拟构造器模式)

&#x1f50d;目的 为创建一个对象定义一个接口&#xff0c;但是让子类决定实例化哪个类。工厂方法允许类将实例化延迟到子类 &#x1f50d;解释 真实世界例子 铁匠生产武器。精灵需要精灵武器&#xff0c;而兽人需要兽人武器。根据客户来召唤正确类型的铁匠。 通俗描述 它为类…

视频汇聚管理平台EasyCVR程序报错“create jwtSecret del server class:0xf98b6040”的原因排查与解决

国标GB28181协议EasyCVR安防视频监控平台可以提供实时远程视频监控、视频录像、录像回放与存储、告警、语音对讲、云台控制、平台级联、磁盘阵列存储、视频集中存储、云存储等丰富的视频能力&#xff0c;平台支持7*24小时实时高清视频监控&#xff0c;能同时播放多路监控视频流…

【学习笔记】Windows GDI绘图(八)画笔Pen与画刷Brush

文章目录 关于Pen改变Pen的宽度width和对齐方式Alignment带线帽的线段连接线条LineJoin自定义虚线用纹理填充线条 关于BrushHatchBrush阴影LinearGradientBrush线性渐变PathGradientBrush 详细示例Pen与Brush的属性与方法 关于Pen 改变Pen的宽度width和对齐方式Alignment 可以…

IntelliJ IDEA Ultimate 2024.1 Mac激活码 Java开发首选IDE

IntelliJ IDEA Ultimate 2024 搜Mac软件之家下载IDEA Mac中文版 IntelliJ IDEA Ultimate 2024是JetBrains公司推出的一款功能强大的集成开发环境&#xff08;IDE&#xff09;&#xff0c;专为专业开发者设计&#xff0c;支持多种编程语言和框架。它提供了一系列高级功能&…

【免费Web系列】JavaWeb实战项目案例五

这是Web第一天的课程大家可以传送过去学习 http://t.csdnimg.cn/K547r 新增员工 前面我们已经实现了员工信息的条件分页查询。 那今天我们要实现的是新增员工的功能实现&#xff0c;页面原型如下&#xff1a; ​ 首先我们先完成"新增员工"的功能开发&#xff0…

Linux--线程的分离、线程库的地址关系的理解、线程的简单封装(二)

线程系列&#xff1a; 线程的认识&#xff1a;讲解线程的概念和线程的基本控制 线程的分离 线程分离是指将一个线程从主线程中分离出来&#xff0c;使其能够独立运行。当一个线程被设置为分离状态时&#xff0c;它结束时系统会自动回收其资源&#xff0c;而不需要其他线程使用…

【喜报】科大睿智服务企业通过CMMI3级认证

​北京建投科信科技发展股份有限公司&#xff08;以下简称“北京建投科技” &#xff09;前身为北京银帝科技发展公司&#xff0c;成立于1993年&#xff0c;注册资本6,000万元&#xff0c;为中国建银投资有限责任公司&#xff08;简称“中国建投”&#xff09;的成员企业建投华…

ovs-vsctl错误:Port does not contain a column whoes name matches “--id“

出错的命令是: ovs-vsctl -- set Bridge br-int mirrors=@m -- --id=@snooper0 get Port snooper0\ -- --id=@patch-tun get Port patch-tun -- --id=@m create Mirror name=mymirror \ select