Codeforces Round 1034 (Div. 3)

比赛链接如下:https://codeforces.com/contest/2123 

A. Blackboard Game

Initially, the integers from 00 to n−1 are written on a blackboard.

In one round,

  • Alice chooses an integer a on the blackboard and erases it;
  • then Bob chooses an integer b on the blackboard such that a+b≡3(mod4) and erases it.

Rounds take place in succession until a player is unable to make a move — the first player who is unable to make a move loses. Determine who wins with optimal play.

We define that x≡y(mod m) whenever x−y is an integer multiple of mm.

解题思路:

其实根据输入输出也能大概猜出来

(a+b-3)%4=0, Alice去拿一个数, 然后Bob去进行配对, 谁先操作不了, 谁就输了

eg:

n=4, 0 1 2 3

Alice拿0, Bob拿3进行配对

Alice拿1, Bob拿2进行配对

Bob赢

n=5, 0 1 2 3 4

这里Alice先拿0还是4无所谓,

Alice赢

n=8 0 1 2 3 ; 4 5 6 7

Bob赢

n%4==0, Bob赢

n%4!=0, Alice赢

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {ll n;cin >> n;if (n % 4 == 0) {cout << "Bob" << endl;} else {cout << "Alice" << endl;}
}
int main() {int t;cin >> t;while (t--) {solve();}return 0;
}

 B. Tournament

You are given an array of integers a1,a2,…,an. A tournament is held with nn players. Player i has strength aiai.

While more than k players remain,

  • Two remaining players are chosen at random;
  • Then the chosen player with the lower strength is eliminated. If the chosen players have the same strength, one is eliminated at random.

Given integers j and k (1≤j,k≤n), determine if there is any way for player j to be one of the last k remaining players.

解题思路:

当k=1时, aj要想留下来, 只能是数组最大值, 

k>1时, aj肯定是能留下来的

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {int n, j, k;cin >> n >> j >> k;j--;vector<int> a(n);for (int i = 0; i < n; i++) {cin >> a[i];}if (k == 1) {int mx = *max_element(a.begin(), a.end());if (a[j] == mx) {cout << "YES" << endl;} else {cout << "NO" << endl;}} else {cout << "YES" << endl;}
}
int main() {int t;cin >> t;while (t--) {solve();}return 0;
}

 C. Prefix Min and Suffix Max

You are given an array aa of distinct integers.

In one operation, you may either:

  • choose a nonempty prefix of aa and replace it with its minimum value, or
  • choose a nonempty suffix of aa and replace it with its maximum value.

Note that you may choose the entire array a.

For each element ai, determine if there exists some sequence of operations to transform aa into [ai]; that is, make the array a consist of only one element, which is aiai. Output your answer as a binary string of length nn, where the ii-th character is 1 if there exists a sequence to transform aa into [ai], and 0 otherwise.

A prefix of an array is a subarray consisting of the first kk elements of the array, for some integer k.

A suffix of an array is a subarray consisting of the last k elements of the array, for some integer k.

给你一个不同整数的数组。
在一个操作中,您可以选择a的非空前缀*并将其替换为其最小值,或者选择a的非空前缀*并将其替换为其最大值。
注意,您可以选择整个数组a。对于每个元素a¿,确定是否存在一些操作序列将a转换为[a´];
也就是说,使数组只包含一个元素,即a。将您的答案输出为长度为n的二进制字符串,如果存在将a转换为[ai]的序列,则第i个字符为1,否则为0。
对于整数k,数组的前缀是由数组的前k个元素组成的子数组。数组的后缀是由数组的最后k个元素组成的子数组。 

解题思路:

​​​​​​1.前缀最小值:元素 ai 是从数组开头到 i 位置(a1 到 ai)的最小值。

2.后缀最大值:元素 ai 是从 i 位置到数组结尾(ai 到 an)的最大值。

3.可保留条件:如果 ai 是前缀最小值或后缀最大值,则存在操作序列将数组缩减为 [ai];否则,无法保留。

eg: 数组 [1, 3, 5, 4, 7, 2],输出 100011

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {int n;cin >> n;vector<int> a(n + 1), pre(n + 1, INT_MAX), suf(n + 2);for (int i = 1; i <= n; i++) {cin >> a[i];pre[i] = min(pre[i - 1], a[i]);}for (int i = n; i >= 1; i--) {suf[i] = max(suf[i + 1], a[i]);}for (int i = 1; i <= n; i++) {cout << (a[i] == pre[i] || a[i] == suf[i] ? 1 : 0);}cout << endl;
}int main() {int t;cin >> t;while (t--) {solve();}return 0;
}

 D. Binary String Battle

Alice and Bob are given a binary string s of length n, and an integer k (1≤k<n).

Alice wins if she is able to transform all characters of ss into zeroes. If Alice is unable to win in a finite number of moves, then Bob wins.

Alice and Bob take turns, with Alice going first.

  • On Alice's turn, she may choose any subsequence∗∗ of length k in s, then set all characters in that subsequence to zero.
  • On Bob's turn, he may choose any substring†† of length k in ss, then set all characters in that substring to one.

Note that Alice wins if the string consists of all zeros at any point during the game, including in between Alice's and Bob's turns.

Determine who wins with optimal play.

∗∗A subsequence of a string s is a set of characters in s. Note that these characters do not have to be adjacent.

††A substring of a string s is a contiguous group of characters in s. Note that these characters must be adjacent.

解题思路:

1.Alice必赢的条件:
如果初始 cnt(s 中 1 的数量) ≤ k,Alice 一次就能把所有 1 清掉 —— 赢。
如果 n < 2*k,则 Bob 无法每次维护 cnt > k 的策略(因为没地方藏一个"额外的 1")—— Alice 
2. Bob必赢的条件:
如果 cnt > k 且 n ≥ 2*k,Bob 总能维护至少一个额外的 1,并总能抵消 Alice 的操作 —— 赢。 

因为你要找两个不重叠的长度为 k 的子串,至少需要长度 2k

否则他怎么也得和 Alice 的[清除区]发生重叠,Alice 就能全清了

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve(){int n, k, cnt = 0;string s;cin >> n >> k >> s;for(char c : s){if(c == '1'){cnt++;}}cout << (cnt <= k || n < 2*k ? "Alice" : "Bob") << '\n';
}int main(){int t;cin >> t;while(t--) {solve();}return 0;
}

E. MEX Count

Define the MEX (minimum excluded value) of an array to be the smallest nonnegative integer not present in the array. For example,

  • MEX([2,2,1])=0 because 0 is not in the array.
  • MEX([3,1,0,1])=2 because 0 and 1 are in the array but 2 is not.
  • MEX([0,3,1,2])=4 because 0, 1, 2, and 3 are in the array but 44 is not.

You are given an array aa of size n of nonnegative integers.

For all k (0≤k≤n), count the number of possible values of MEX(a) after removing exactly kk values from a.

解题思路:MEX是数组a中的最小非负整数

eg:

数组a: 

0 1 2 3 4 5 .. n

出现次数分别为:

1 2 1 3 0 2 .. 5

比如MEX=1, 我们最少需要删除2个1

最多为n-1 (1之前每个数字次数剩1个,1后面全删了,最后剩1个数字,删除n-1个)

就是你删除任意个[cntx, n-x] 都能得到x

题目是删除k个数字, mex的可能性

然后差分即可

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {int t;cin >> t;while (t--) {int n;cin >> n;vector<int> a(n), cnt(n + 1, 0);for (int i = 0; i < n; i++) {cin >> a[i];if (a[i] <= n) {cnt[a[i]]++;}}vector<int> ok(n + 1, false);ok[0] = true;for (int m = 1; m <= n; m++) {ok[m] = ok[m - 1] && (cnt[m - 1] > 0);}vector<int> diff(n + 2, 0);for (int m = 0; m <= n; m++) {if (!ok[m])break;int L = cnt[m];int R = n - m;if (L <= R) {diff[L] += 1;diff[R + 1] -= 1;}}vector<int> ans(n + 1);int cur = 0;for (int k = 0; k <= n; k++) {cur += diff[k];ans[k] = cur;}for (int k = 0; k <= n; k++) {cout << ans[k] << (k == n ? '\n' : ' ');}}return 0;
}

 F. Minimize Fixed Points

Call a permutation∗ p of length nn good if gcd(pi,i)>1 for all 2≤i≤n. Find a good permutation with the minimum number of fixed points‡‡ across all good permutations of length n. If there are multiple such permutations, print any of them.

∗∗ A permutation of length nn is an array that contains every integer from 1 to n exactly once, in any order.

gcd(x,y) denotes the greatest common divisor (GCD) of x and y.

‡‡A fixed point of a permutation p is an index j (1≤j≤n) such that pj=j.

解题思路:

n=6,

1 4 6 2 5 3

1 2 3 4 5 6

gcd:

1 2 3 2 5 3

fixed points = 2

gcd(pi,i)>1, i>1

i=0, a[0]=1

当n=13,

质数2及其倍数为:2  4  6  8 10 12 

数左移一位, 就可以和下标形成 gcd(pi,i)=2

2 4 6 8 10 12

4 6 8 10 12 2

prime = 3

3 6 9 12

素数越大, 在1-n这个序列中, 倍数的出现次数越少  

prime=5

5 10

只能这两进行轮换, 因此我们从prime比较大 -> prime比较小

prime在比较大的数轮换过后, 后续就不需要进行轮换了

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 1000005;
vector<bool> isp(MAXN, true); // isp[i] = true 表示是素数
void init(int n) {isp[0] = isp[1] = false;for (int i = 2; i * i <= n; i++) {if (isp[i]) {for (int j = i * i; j <= n; j += i) {isp[j] = false;}}}
}void solve() {int n;cin >> n;init(n);vector<int> a(n + 1, -1);vector<bool> vis(n + 1, false);for (int i = n / 2; i >= 2; i--) {if (!isp[i]) {continue;}vector<int> c;    收集所有 i 的倍数for (int j = i; j <= n; j += i) {if (vis[j]) {continue;}vis[j] = true;c.push_back(j);}// // 构造一个环:c[0]->c[1]->...->c[k-1]->c[0]for (int j = 0; j < c.size(); j++) {a[c[j]] = c[(j + 1) % c.size()];}}for (int i = 1; i <= n; i++) {cout << (a[i] == -1 ? i : a[i]) << " ";}cout << '\n';
}
int main() {int t;cin >> t;while (t--) {solve();}return 0;
}

G. Modular Sorting

 You are given an integer m (2≤m≤5⋅105) and an array aa consisting of nonnegative integers smaller than m.

Answer queries of the following form:

  • 1 i x: assign ai:=x
  • 2 k: in one operation, you may choose an element aiai and assign ai:=(ai+k)(modm)a — determine if there exists some sequence of (possibly zero) operations to make a nondecreasing.

Note that instances of query 2 are independent; that is, no actual operations are taking place. Instances of query 1 are persistent.

a(modm) is defined as the unique integer bb such that 0≤b<m and a−b is an integer multiple of m.

An array a of size n is called nondecreasing if and only if ai≤ai+1 for all 1≤i<n.

解题思路:

(ai+k)%m 

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 1000100;
vector<bool> isp;
vector<int> primes;void init(int top) {isp.assign(top + 1, true);isp[0] = isp[1] = false;for (int i = 2; i <= top; ++i) {if (isp[i])primes.push_back(i);for (int j = 0; j < (int)primes.size(); ++j) {int p = primes[j];if (i * p > top)break;isp[i * p] = false;if (i % p == 0)break;}}
}map<int, int> factorize(int v) {map<int, int> res;for (int i = 0; i < (int)primes.size(); ++i) {int p = primes[i];if (1LL * p * p > v)break;int cnt = 0;while (v % p == 0) {cnt++;v /= p;}if (cnt)res[p] = cnt;}if (v > 1)res[v] = 1;return res;
}vector<int> get_divisors(int v) {map<int, int> f = factorize(v);vector<int> res;res.push_back(1);for (map<int, int>::iterator it = f.begin(); it != f.end(); ++it) {int p = it->first, c = it->second;int sz = res.size();int base = 1;for (int i = 0; i < c; ++i) {base *= p;for (int j = 0; j < sz; ++j) {res.push_back(res[j] * base);}}}return res;
}int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }void solve() {int n, m, qn;cin >> n >> m >> qn;vector<int> a(n);for (int i = 0; i < n; i++)cin >> a[i];vector<array<int, 3>> q(qn);for (int i = 0; i < qn; i++) {cin >> q[i][0];if (q[i][0] == 1) {cin >> q[i][1] >> q[i][2];} else {cin >> q[i][1];}}vector<int> res(qn, -1);vector<int> b(n);vector<int> divisors = get_divisors(m);for (int d_index = 0; d_index < (int)divisors.size(); ++d_index) {int d = divisors[d_index];for (int i = 0; i < n; i++) {b[i] = a[i] % d;}int sum = 0;for (int i = 0; i + 1 < n; i++) {if (b[i] > b[i + 1])sum++;}for (int i = 0; i < qn; i++) {if (q[i][0] == 1) {int w = q[i][1] - 1;int v = q[i][2];if (w - 1 >= 0 && b[w - 1] > b[w])sum--;if (w + 1 < n && b[w] > b[w + 1])sum--;b[w] = v % d;if (w - 1 >= 0 && b[w - 1] > b[w])sum++;if (w + 1 < n && b[w] > b[w + 1])sum++;} else {if (gcd(q[i][1], m) == d) {res[i] = sum < m / d;}}}}for (int i = 0; i < qn; i++) {if (res[i] != -1) {cout << (res[i] ? "YES" : "NO") << '\n';}}
}int main() {init(MAXN);int t;cin >> t;while (t--) {solve();}return 0;
}

感谢大家的点赞和关注,你们的支持是我创作的动力!

 

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

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

相关文章

微电网系列之微电网的孤岛运行

个人主页&#xff1a;云纳星辰怀自在 座右铭&#xff1a;“所谓坚持&#xff0c;就是觉得还有希望&#xff01;” 微电网的孤岛运行 微电网具有并网和孤岛两种运行模式&#xff0c;由于孤岛运行模式下&#xff0c;分布式电源为微电网内部负荷提供频率和电压支撑&#xff0c;由…

JsonCpp的核心类及核心函数使用汇总

文章目录 JsonCpp的核心类及核心函数使用汇总一、前言二、JsonCpp 核心类介绍三、Value 类函数解析1. 值获取函数&#xff08;asxxx 系列 &#xff09;2. 值类型判断函数&#xff08;isxxx 系列 &#xff09;3. 数组操作函数4. 对象操作函数5. 运算符重载6. 迭代器7. JSON 转化…

Qt写入excel

1.tableView导出到excel 点击导出函数按钮、发送sendMessage信号&#xff08;信号名称&#xff0c;对象&#xff0c;数据&#xff09; void HydroelectricPowerPluginImpl::exportTableViewSelectedRows(QTableView* tableView, QWidget* parent) {if (!tableView || !tableVie…

OSCP - Proving Grounds - DC - 1

主要知识点 drupal 7 RCEfind SUID提权 具体步骤 nmap起手,80端口比较有意思&#xff0c;安装了 Drupal 7 Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-12-17 14:23 UTC Nmap scan report for 192.168.57.193 Host is up (0.00087s latency). Not shown: 65531 cl…

仿小红书交流社区(微服务架构)

文章目录 framework - 平台基础设施starter - jacksoncommonexceptionresponseutil starter - content 全局上下文distributed - id - generate - 分布式 IdSnowflake - 基于雪花算法生成 IdSegment - 基于分段式生成 Id OSS - 对象存储KV - 短文本存储笔记评论 user - 用户服务…

大模型开源技术解析 4.5 的系列开源技术解析:从模型矩阵到产业赋能的全栈突破

提示&#xff1a;本篇文章 1300 字&#xff0c;阅读时间&#xff1a;5分钟。 前言 6 月 30 日&#xff0c;百度正式开源文心大模型 4.5 系列&#xff0c;这一动作不仅兑现了 2 月发布会上的技术承诺&#xff0c;更以 10 款全维度模型矩阵刷新了国内开源模型的技术边界。从学术…

[6-02-01].第05节:配置文件 - YAML配置文件语法

SpringBoot学习大纲 一、YAML语法 1.1.概述&#xff1a; 1.YAML是一种数据序列化格式&#xff1b;2.它是以数据为中心3.容易阅读&#xff0c;容易与脚本语言交互,如下图所示&#xff1a; 1.2.基本语法 1.key: value&#xff1a;kv之间有空格2.使用缩进表示层级关系3.缩进时…

FPGA学习

一、module : 定义&#xff1a; 是构建数字系统的基本单元&#xff0c;用于封装电路的结构和行为。它可以表示从简单的逻辑门到复杂的处理器等任何硬件组件。 1. module 的基本定义 module 模块名 (端口列表);// 端口声明input [位宽] 输入端口1;output [位宽] 输出端口1;ino…

26-计组-存储器与Cache机制

一、存储器与局部性原理 1. 局部性原理 基础概念&#xff1a; 时间局部性&#xff1a;一个存储单元被访问后&#xff0c;短时间内可能再次被访问&#xff08;例如循环变量&#xff09;。空间局部性&#xff1a;一个存储单元被访问后&#xff0c;其附近单元可能在短时间内被访…

I/O 线程 7.3

前言 以下&#xff1a; 概述 1.基础 2.代码演示 3.练习 4.分析题 1.基础 一、线程基础概念 并发执行原理 通过时间片轮转实现多任务"并行"效果 实际为CPU快速切换执行不同线程 线程 vs 进程 线程共享进程地址空间&#xff0c;切换开销更小 进程拥有独立资源&am…

MySQL JSON数据类型完全指南:从版本演进到企业实践的深度对话

&#x1f4ca; MySQL JSON数据类型完全指南&#xff1a;从版本演进到企业实践的深度对话 在当今数据驱动的时代&#xff0c;MySQL作为最受欢迎的关系型数据库之一&#xff0c;不断演进以满足现代应用的需求。JSON数据类型的引入&#xff0c;让MySQL在保持关系型数据库优势的同时…

BI × 餐饮行业 | 以数据应用重塑全链路业务增长路径

在竞争激烈的餐饮行业中&#xff0c;数据已成为企业保持竞争力的关键资产。通过深入分析顾客数据&#xff0c;餐饮企业能够洞察消费者的需求和偏好&#xff0c;从而提供更加精准和个性化的服务。此外&#xff0c;利用数据优化业务管理&#xff0c;降低成本&#xff0c;并提高运…

【学习线路】机器学习线路概述与内容关键点说明

文章目录 零、机器学习的企业价值一、基础概念1. 机器学习定义2. 学习类型3. 学习范式 二、核心算法与技术1. 监督学习2. 无监督学习3. 模型评估与优化 三、深度学习与神经网络1. 神经网络基础2. 深度学习框架3. 应用场景 四、工具与实践1. 数据处理2. 模型部署3. 机器学习的生…

Linux 命令:cp

Linux cp 命令详细教程 cp 是 Linux 系统中最常用的命令之一&#xff0c;用于复制文件或目录。它可以将源文件/目录复制到指定的目标位置&#xff0c;支持批量复制、强制覆盖、保留文件属性等功能。下面详细介绍其用法。资料已经分类整理好&#xff1a;https://pan.quark.cn/s…

java分页插件| MyBatis-Plus分页 vs PageHelper分页:全面对比与最佳实践

MyBatis-Plus分页 vs PageHelper分页&#xff1a;全面对比与最佳实践 一、分页技术概述 在Java持久层框架中&#xff0c;分页是高频使用的功能。主流方案有&#xff1a; MyBatis-Plus分页&#xff1a;MyBatis增强工具的内置分页方案PageHelper分页&#xff1a;独立的MyBatis…

PROFINET转MODBUS TCP网关在机械臂通信操作中的应用研究

在特定的汽车零部件生产工厂焊接生产线上&#xff0c;机械臂被应用于焊接作业&#xff0c;其控制体系基于Profinet协议。同时&#xff0c;工厂的自动化控制体系以西门子S7-1200PLC为核心&#xff0c;通过ModbusTCP协议实现数据交换。为实现焊接过程的自动化控制以及生产数据的实…

Mac中如何Chrome禁用更新[update chflags macos]

写在前面 在 macOS 系统中&#xff0c;系统更新提示的小红点常常让人不胜其扰。 尤其是当你希望保持现有系统的稳定性&#xff0c;或因兼容性问题暂不想升级时&#xff0c;这个小红点就像一个顽固的提醒。 - windowsMac版直接删除更新程序, 有效 cd ~/Library/Google/Googl…

LoRA使用-多个LoRA

LoRA的风格分类 不用去记它有什么很特别的风格&#xff0c;简单来说基础模型就像一个全能画手&#xff0c;什么都能画&#xff0c;而LoRA是在某个风格中经过特训的它的一个分身。使得它更精通该风格。 关于LoR风格分类&#xff1a;提示词撰写公式 Checkpoint&LoRA对比 训…

牛客刷题 — 【排序】[NOIP2012] 国王的游戏(高精度结构体排序)

1.题面&#xff1a;传送门 2. 思路&#xff1a; 相邻的两个大臣的先后顺序只会互相影响&#xff0c;并不会影响其他人的金币数。 假设前 i-1 个人左手上的数乘积为 s 。 ① 若 A 大臣排在B 大臣的前面&#xff0c;则&#xff1a; s 此时的金币数最大值为 。 ② 若B大臣排…

grpc 和限流Sentinel

基于gRPC的微服务通信模块技术方案书 1. 总体架构设计 #mermaid-svg-TiN9cudEfW5mCWHm {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-TiN9cudEfW5mCWHm .error-icon{fill:#552222;}#mermaid-svg-TiN9cudEfW5mCWHm…