当前位置: 首页 > news >正文

CodeTON Round 6 (Div 1 + Div 2, Rated, Prizes!)(A - E)

CodeTON Round 6 (Div. 1 + Div. 2, Rated, Prizes!)(A - E)

CodeTON Round 6 (Div. 1 + Div. 2, Rated, Prizes!)

A. MEXanized Array(分类讨论)

可以发现当 n < k 或者 k > x + 1 的时候无法构成 , 其余的时候贪心的用 x 最大化贡献即可 , 注意特判 k == x 的情况。

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
const int N = 2e6 + 10;
const int mod = 1e9 + 7;
typedef pair<int,int>PII;int t , n , k , x; signed main(){IOScin >> t;while(t --) {cin >> n >> k >> x;if(n < k || k > x + 1) {cout << "-1\n";} else {int res = 0;int now = k - 1;res += (now + 1) * now / 2;if(k == x) res += (x - 1) * (n - k);else res += x * (n - k);cout << res << "\n";}}return 0;
}
//freopen("文件名.in","r",stdin);
//freopen("文件名.out","w",stdout);

B. Friendly Arrays(位运算)

观察或运算发现 , 只有当前位为 1 的时候或运算才能对结果产生影响 , 且是把所有数当前位全部变成 1 , 不妨对 n 的奇偶进行讨论 ,模拟完可以发现这样的一个性质 , 当 n 为奇数的时候操作异或和会变大 , 偶数的时候操作异或和会变小 , 所以最大最小值一定是全操作和全不操作的 , 计算即可。

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
const int N = 2e6 + 10;
const int mod = 1e9 + 7;
typedef pair<int,int>PII;int n , m , t;
int a[N] , b[N];signed main(){IOScin >> t;while(t --) {cin >> n >> m;int mx = 0 , mn = 0 , k = 0;for(int i = 1 ; i <= n ; i ++) cin >> a[i];for(int i = 1 ; i <= m ; i ++) cin >> b[i] , k |= b[i];for(int i = 1 ; i <= n ; i ++) {mn ^= (a[i] | k);mx ^= a[i];}if(mn > mx) swap(mn , mx);cout << mn << " " << mx << "\n";}return 0;
}
//freopen("文件名.in","r",stdin);
//freopen("文件名.out","w",stdout);

C. Colorful Table(思维 ,排序)

不难发现对于每个数来说 , 我们要找大于等于本身的最靠左的位置和最靠右的位置 , 考虑按照值的大小升序排序 , 这样问题就转化成找排序后每个值右边序号的最大值和最小值 , 逆序扫一遍 , 边扫便维护即可。

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
const int N = 2e6 + 10;
const int mod = 1e9 + 7;
typedef pair<int,int>PII;int t , n , k , ans[N];
struct node {int x , id;
}a[N];signed main(){IOScin >> t;while(t --) {cin >> n >> k;for(int i = 1 ; i <= n ; i ++) {cin >> a[i].x ;a[i].id = i;}sort(a + 1 , a + 1 + n ,[&](node a, node b){return a.x < b.x;});int mx = -9e18 , mn = 9e18;for(int i = n ; i >= 1 ; i --){int now = a[i].x;int id  = a[i].id;mx = max(mx , id);mn = min(mn , id);ans[now] = (mx - mn + 1) * 2;}for(int i = 1 ; i <= k ; i ++) {cout << ans[i] << " ";ans[i] = 0;}cout << "\n";}return 0;
}
//freopen("文件名.in","r",stdin);
//freopen("文件名.out","w",stdout);

D. Prefix Purchase(贪心)

首先不难想到,贪心的取次数最多且最靠右的位置 , 但这样显然不是最优的 , 因为有

3 4 5

11

这种情况 , 我们可以通过替换的方式更充分的利用余数 ,转化一下不难发现如何利用余数的问题和开始要求的问题是一样的(选 4 还是选 5去替换 3 就相当于 k = 2 时 , 选 1 还是 选 2 能让字典序变大) , 不断贪心的选把余数用完即可.

例如 :

3 4 5

11

第一次贪心之后会变成

0 1 2

2

第二次贪心之后会变成

0 0 1

0

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
const int N = 2e6 + 10;
const int mod = 1e9 + 7;
typedef pair<int,int>PII;int t , n , k;
int a[N] , pre[N] , b[N];signed main(){IOScin >> t;while(t --) {cin >> n;pre[0] = 0;for(int i = 1 ; i <= n ; i ++) cin >> a[i] , pre[i] = 0;cin >> k;int id = 0;while(k && id != -1) {int maxx = 0 , id1 = -1;for(int i = n ; i >= id + 1 ; i --) {if((k / a[i]) > maxx) {maxx = k / a[i];id1  = i;} }k -= maxx * a[id1];for(int i = n ; i >= id1 + 1 ; i --) {a[i] -= a[id1];}pre[id]    += maxx;pre[id1]   -= maxx;id = id1;}int sum = 0;for(int i = 1 ; i <= n ; i ++) {sum += pre[i - 1];cout << sum << " ";}cout << "\n";}return 0;
}
//freopen("文件名.in","r",stdin);
//freopen("文件名.out","w",stdout);

E. Another MEX Problem(dp)

先考虑 O(n^3) 的解决方法

d p [ i ] [ j ] 表示前 i 个数是否能表示出 j dp[i][j] 表示前 i 个数是否能表示出 j dp[i][j]表示前i个数是否能表示出j

考虑转移

若当前位不选进区间 dp[i][j] = dp[i - 1][j];

若当前位选进区间 , 枚举以当前位为右边界的区间 , 进行转移

dp[i][j] |= dp[l - 1][j ^ mex[l][i]]

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
const int N = 5e3 + 10;
const int mod = 1e9 + 7;
typedef pair<int,int>PII;int t , n ;signed main(){IOScin >> t;while(t --) {cin >> n;		vector<int>a(n + 1);for(int i = 1 ; i <= n ; i ++) {cin >> a[i];}vector<vector<int>>mex(n + 1 , vector<int>(n + 1));vector<vector<bool>>dp(n + 1 , vector<bool>(1 << 13));for(int i = 1 ; i <= n ; i ++) {int now = 0;vector<bool>vis(n + 1);for(int j = i ; j <= n ; j ++) {vis[a[j]] = 1;while(vis[now]) now += 1;mex[i][j] = now;	}}dp[0][0] = 1;for(int i = 1 ; i <= n ; i ++) {//从上一位自然转移dp[i] = dp[i - 1];	for(int l = 1 ; l <= i ; l ++) {for(int k = 0 ; k < (1 << 13) ; k ++) {if(dp[l - 1][k]) dp[i][k ^ mex[l][i]] = 1;}}}int res = 0;for(int i = 0 ; i < (1 << 13) ; i ++) {if(dp[n][i]) res = max(res , i);}cout << res << "\n";}return 0;
}
//freopen("文件名.in","r",stdin);
//freopen("文件名.out","w",stdout);

考虑优化:

1:首先对于相同的右边界 , 我们枚举左边界的时候从大到小 , 由于我们是先从大的范围开始枚举 , 所以每个 mex 只更新一次即可。

2.其次对于相同的左边界 , 每个 mex 更新一次即可 。

显然能凑出来的mex的数量级是O(n)的 , 更新次数也是O(n)的

总复杂度

O ( n 2 ) O(n^2) O(n2)

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
const int N = 5e3 + 10;
const int mod = 1e9 + 7;
typedef pair<int,int>PII;int t , n ;signed main(){IOScin >> t;while(t --) {cin >> n;vector<int>a(n + 1);for(int i = 1 ; i <= n ; i ++) {cin >> a[i];}vector<vector<int>>mex(n + 1 , vector<int>(n + 1));vector<vector<bool>>dp(n + 1 , vector<bool>(1 << 13));for(int i = 1 ; i <= n ; i ++) {int now = 0;vector<bool>vis(n + 1);for(int j = i ; j <= n ; j ++) {vis[a[j]] = 1;while(vis[now]) now += 1;mex[i][j] = now;	}}dp[0][0] = 1;vector<vector<bool>>visl(n + 1 , vector<bool>(1 << 13));vector<vector<bool>>visr(n + 1 , vector<bool>(1 << 13));for(int i = 1 ; i <= n ; i ++) {//从上一位自然转移dp[i] = dp[i - 1];for(int l = i ; l >= 1 ; l --) {if(visr[i][mex[l][i]]) continue;if(visl[l][mex[l][i]]) continue;visl[l][mex[l][i]] = 1;visr[i][mex[l][i]] = 1;for(int k = 0 ; k < (1 << 13) ; k ++) {if(dp[l - 1][k]) dp[i][k ^ mex[l][i]] = 1;}}}int res = 0;for(int i = 0 ; i < (1 << 13) ; i ++) {if(dp[n][i]) res = max(res , i);}cout << res << "\n";}return 0;
}
//freopen("文件名.in","r",stdin);
//freopen("文件名.out","w",stdout);

相关文章:

CodeTON Round 6 (Div 1 + Div 2, Rated, Prizes!)(A - E)

CodeTON Round 6 (Div. 1 Div. 2, Rated, Prizes!)(A - E) CodeTON Round 6 (Div. 1 Div. 2, Rated, Prizes!) A. MEXanized Array&#xff08;分类讨论&#xff09; 可以发现当 n < k 或者 k > x 1 的时候无法构成 &#xff0c; 其余的时候贪心的用 x 最大化贡献即…...

Spring 源码分析(五)——Spring三级缓存的作用分别是什么?

Spring 的三级缓存是经典面试题&#xff0c;也会看到一些文章讲三级缓存与循环依赖之的关系。那么&#xff0c;三级缓存分别存储的什么呢&#xff1f;他们的作用又分别是什么&#xff1f; 一、一、二级缓存 一级缓存是一个名为 singletonObjects 的 ConcurrentHashMap&#x…...

Django基于类视图实现增删改查

第一步&#xff1a;导入View from django.views import View 第二步&#xff1a;新建这个基类 class CLS_executer(View):db DB_executerdef get(self, request):executer_list list(self.db.objects.all().values())return HttpResponse(json.dumps(executer_list), conte…...

matplotlib绘图实现中文宋体的两种方法(亲测)

方法一&#xff1a;这种方法我没有测试。 第一步 找宋体字体 &#xff08;win11系统&#xff09; 2.matplotlib字体目录&#xff0c;如果不知道的话&#xff0c;可以通过以下代码查询&#xff1a; matplotlib.matplotlib_fname() 如果你是Anaconda3 安装的matplotlib&#x…...

非常有用的JavaScript高阶面试技巧!

&#x1f340;一、闭包 闭包是指函数中定义的函数&#xff0c;它可以访问外部函数的变量。闭包可以用来创建私有变量和方法&#xff0c;从而保护代码不受外界干扰。 // 例1 function outerFunction() {const privateVariable "私有变量";function innerFunction()…...

windows 安装Linux子系统 Ubuntu 并配置python3

环境说明&#xff1a; Windows 11 Ubuntu 20.04.6 安装步骤以及问题&#xff1a; 1、开启Windows Subsystem for Linux dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart 2、开启虚拟机特性 dism.exe /online /enabl…...

pytorch的pixel_shuffle转tflite文件

torch.pixel_shuffle()是pytorch里面上采样比较常用的方法&#xff0c;但是和tensoflow的depth_to_space不是完全一样的&#xff0c;虽然看起来功能很像&#xff0c;但是细微是有差异的 def tf_pixelshuffle(input, upscale_factor):temp []depth upscale_factor *upscale_f…...

sentinel-dashboard-1.8.0.jar开机自启动脚本

启动阿里巴巴的流控组件控制面板需要运行一个jar包&#xff0c;通常需要运行如下命令&#xff1a; java -server -Xms4G -Xmx4G -Dserver.port8080 -Dcsp.sentinel.dashboard.server127.0.0.1:8080 -Dproject.namesentinel-dashboard -jar sentinel-dashboard-1.8.0.jar &…...

c++堆排序-建堆-插入-删除-排序

本文以大根堆为例&#xff0c;用数组实现&#xff0c;它的nums[0]是数组最大值。 时间复杂度分析&#xff1a; 建堆o(n) 插入删除o(logn) 堆排序O(nlogn) 首先上代码 #include<bits/stdc.h>using namespace std; void down(vector<int>&nums, int idx, i…...

使用代理后pip install 出现ssl错误

window直接设置代理 httphttp://127.0.0.1:7890;httpshttp://127.0.0.1...

护眼灯什么价位的好?最具性价比的护眼台灯推荐

到了晚上光线比较弱&#xff0c;这时候就需要开灯&#xff0c;要是孩子需要近距离看字学习等等&#xff0c;给孩子选择的灯具要特别的重视。护眼灯就是目前颇受学生家长青睐的灯具之一&#xff0c;越来越多的人会购买一个护眼灯给自己的孩子让孩子能够在灯光下学习的时候&#…...

vue event bus 事件总线

vue event bus 事件总线 创建 工程&#xff1a; H:\java_work\java_springboot\vue_study ctrl按住不放 右键 悬着 powershell H:\java_work\java_springboot\js_study\Vue2_3入门到实战-配套资料\01-随堂代码素材\day04\准备代码\08-事件总线-扩展 vue --version vue crea…...

深信服云桌面用户忘记密码后的处理

深信服云桌面用户忘记了密码&#xff0c;分两种情况&#xff0c;一个是忘记了登录深信服云桌面的密码&#xff0c;另外一个是忘记了进入操作系统的密码。 一、忘记了登录深信服云桌面的密码 登录虚拟桌面接入管理系统界面&#xff0c;在用户管理中选择用户后&#xff0c;点击后…...

Cocos Creator3.8 实战问题(一)cocos creator prefab 无法显示内容

问题描述&#xff1a; cocos creator prefab 无法显示内容&#xff0c; 或者只显示一部分内容。 creator编辑器中能看见&#xff1a; 预览时&#xff0c;看不见内容&#xff1a; **问题原因&#xff1a;** prefab node 所在的layer&#xff0c;默认是default。 解决方法&…...

朴素贝叶斯深度解码:从原理到深度学习应用

目录 一、简介贝叶斯定理的历史和重要性定义例子 朴素贝叶斯分类器的应用场景定义例子常见应用场景 二、贝叶斯定理基础条件概率定义例子 贝叶斯公式定义例子 三、朴素贝叶斯算法原理基本构成定义例子 分类过程定义例子 不同变体定义例子 四、朴素贝叶斯的种类高斯朴素贝叶斯&a…...

RUST 每日一省:闭包

Rust中的闭包是一种可以存入外层函数中变量或作为参数传递给其他函数的匿名函数。你可以在一个地方创建闭包&#xff0c;然后在不同的上下文环境中调用该闭包来完成运算。和一般的函数不同&#xff0c;闭包可以从定义它的作用域中捕获值。 语法 闭包由“||”和“{}”组合而成。…...

Ubuntu下文件的解压缩操作:常用zip和unzip

Ubuntu下文件的解\压缩 压缩一个文件夹为zip包&#xff0c;加参数-r&#xff1a; zip -r MyWeb.zip MyWeb需要排除目录里某个文件夹&#xff1f;例如我要去掉node_modules&#xff0c;以显著减小压缩包体积&#xff0c;此时该怎么做&#xff1f; zip -r MyWeb.zip ./MyWeb…...

Linux学习第22天:Linux中断驱动开发(一): 突如其来

Linux版本号4.1.15 芯片I.MX6ULL 大叔学Linux 品人间百味 思文短情长 中断作为驱动开发中很重要的一个概念&#xff0c;在实际的项目实践中经常用到。本节的主要内容包括中断简介、硬件原理分析、驱动程序开发及运行测试。其中驱动程…...

IDEA 2019 Springboot 3.1.3 运行异常

项目场景&#xff1a; 在IDEA 2019 中集成Springboot 3.1.3 框架&#xff0c;运行异常。 <?xml version"1.0" encoding"UTF-8"?><project xmlns"http://maven.apache.org/POM/4.0.0" xmlns:xsi"http://www.w3.org/2001/XMLSch…...

【JAVA】飞机大战

代码和图片放在这个地址了&#xff1a; https://gitee.com/r77683962/fighting/tree/master 最新的代码运行&#xff0c;可以有两架飞机&#xff0c;分别通过WASD&#xff08;方向&#xff09;&#xff0c;F&#xff08;发子弹&#xff09;&#xff1b;上下左右&#xff08;控…...

云原生核心技术 (7/12): K8s 核心概念白话解读(上):Pod 和 Deployment 究竟是什么?

大家好&#xff0c;欢迎来到《云原生核心技术》系列的第七篇&#xff01; 在上一篇&#xff0c;我们成功地使用 Minikube 或 kind 在自己的电脑上搭建起了一个迷你但功能完备的 Kubernetes 集群。现在&#xff0c;我们就像一个拥有了一块崭新数字土地的农场主&#xff0c;是时…...

华为OD机试-食堂供餐-二分法

import java.util.Arrays; import java.util.Scanner;public class DemoTest3 {public static void main(String[] args) {Scanner in new Scanner(System.in);// 注意 hasNext 和 hasNextLine 的区别while (in.hasNextLine()) { // 注意 while 处理多个 caseint a in.nextIn…...

Psychopy音频的使用

Psychopy音频的使用 本文主要解决以下问题&#xff1a; 指定音频引擎与设备&#xff1b;播放音频文件 本文所使用的环境&#xff1a; Python3.10 numpy2.2.6 psychopy2025.1.1 psychtoolbox3.0.19.14 一、音频配置 Psychopy文档链接为Sound - for audio playback — Psy…...

【HTML-16】深入理解HTML中的块元素与行内元素

HTML元素根据其显示特性可以分为两大类&#xff1a;块元素(Block-level Elements)和行内元素(Inline Elements)。理解这两者的区别对于构建良好的网页布局至关重要。本文将全面解析这两种元素的特性、区别以及实际应用场景。 1. 块元素(Block-level Elements) 1.1 基本特性 …...

根据万维钢·精英日课6的内容,使用AI(2025)可以参考以下方法:

根据万维钢精英日课6的内容&#xff0c;使用AI&#xff08;2025&#xff09;可以参考以下方法&#xff1a; 四个洞见 模型已经比人聪明&#xff1a;以ChatGPT o3为代表的AI非常强大&#xff0c;能运用高级理论解释道理、引用最新学术论文&#xff0c;生成对顶尖科学家都有用的…...

Go 语言并发编程基础:无缓冲与有缓冲通道

在上一章节中&#xff0c;我们了解了 Channel 的基本用法。本章将重点分析 Go 中通道的两种类型 —— 无缓冲通道与有缓冲通道&#xff0c;它们在并发编程中各具特点和应用场景。 一、通道的基本分类 类型定义形式特点无缓冲通道make(chan T)发送和接收都必须准备好&#xff0…...

AirSim/Cosys-AirSim 游戏开发(四)外部固定位置监控相机

这个博客介绍了如何通过 settings.json 文件添加一个无人机外的 固定位置监控相机&#xff0c;因为在使用过程中发现 Airsim 对外部监控相机的描述模糊&#xff0c;而 Cosys-Airsim 在官方文档中没有提供外部监控相机设置&#xff0c;最后在源码示例中找到了&#xff0c;所以感…...

Kafka主题运维全指南:从基础配置到故障处理

#作者&#xff1a;张桐瑞 文章目录 主题日常管理1. 修改主题分区。2. 修改主题级别参数。3. 变更副本数。4. 修改主题限速。5.主题分区迁移。6. 常见主题错误处理常见错误1&#xff1a;主题删除失败。常见错误2&#xff1a;__consumer_offsets占用太多的磁盘。 主题日常管理 …...

Python训练营-Day26-函数专题1:函数定义与参数

题目1&#xff1a;计算圆的面积 任务&#xff1a; 编写一个名为 calculate_circle_area 的函数&#xff0c;该函数接收圆的半径 radius 作为参数&#xff0c;并返回圆的面积。圆的面积 π * radius (可以使用 math.pi 作为 π 的值)要求&#xff1a;函数接收一个位置参数 radi…...

【Kafka】Kafka从入门到实战:构建高吞吐量分布式消息系统

Kafka从入门到实战:构建高吞吐量分布式消息系统 一、Kafka概述 Apache Kafka是一个分布式流处理平台,最初由LinkedIn开发,后成为Apache顶级项目。它被设计用于高吞吐量、低延迟的消息处理,能够处理来自多个生产者的海量数据,并将这些数据实时传递给消费者。 Kafka核心特…...