Codeforces Round 930 (Div. 2)(A~B)补题

Codeforces Round 930 Div. 2

  • A. Shuffle Party
    • 1、模拟过程
    • 2、代码
  • B. Binary Path
    • 1、过程模拟
    • 2、代码

A. Shuffle Party

A. Shuffle Party

                                          A. Shuffle Party
                                   time limit per test: 1 second
                               memory limit per test: 256 megabytes
                                       input: standard input
                                       output: standard output

You are given an array a 1 , a 2 , … , a n a_1, a_2, \ldots, a_n a1,a2,,an. Initially, a i = i a_i=i ai=i for each 1 ≤ i ≤ n 1 \le i \le n 1in.
The operation swap ( k ) \texttt{swap}(k) swap(k) for an integer k ≥ 2 k \ge 2 k2 is defined as follows:

  • Let d d d be the largest divisor † ^\dagger of k k k which is not equal to k k k itself. Then swap the elements a d a_d ad and a k a_k ak.
    Suppose you perform swap ( i ) \texttt{swap}(i) swap(i) for each i = 2 , 3 , … , n i=2,3,\ldots, n i=2,3,,n in this exact order. Find the position of 1 1 1 in the resulting array. In other words, find such j j j that a j = 1 a_j = 1 aj=1 after performing these operations.
    † ^\dagger An integer x x x is a divisor of y y y if there exists an integer z z z such that y = x ⋅ z y = x \cdot z y=xz.

Input

Each test contains multiple test cases. The first line contains the number of test cases t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1t104). The description of the test cases follows.
The only line of each test case contains one integer n n n ( 1 ≤ n ≤ 1 0 9 1 \le n \le 10^9 1n109) — the length of the array a a a.

Output

For each test case, output the position of 1 1 1 in the resulting array.

Input
4
1
4
5
120240229

Output
1
4
4
67108864

Note

In the first test case, the array is [ 1 ] [1] [1] and there are no operations performed.

In the second test case, a a a changes as follows:

  • Initially, a a a is [ 1 , 2 , 3 , 4 ] [1,2,3,4] [1,2,3,4].
  • After performing swap ( 2 ) \texttt{swap}(2) swap(2), a a a changes to [ 2 ‾ , 1 ‾ , 3 , 4 ] [\underline{2},\underline{1},3,4] [2,1,3,4] (the elements being swapped are underlined).
  • After performing swap ( 3 ) \texttt{swap}(3) swap(3), a a a changes to [ 3 ‾ , 1 , 2 ‾ , 4 ] [\underline{3},1,\underline{2},4] [3,1,2,4].
  • After performing swap ( 4 ) \texttt{swap}(4) swap(4), a a a changes to [ 3 , 4 ‾ , 2 , 1 ‾ ] [3,\underline{4},2,\underline{1}] [3,4,2,1].

Finally, the element 1 1 1 lies on index 4 4 4 (that is, a 4 = 1 a_4 = 1 a4=1). Thus, the answer is 4 4 4.

1、模拟过程

例如,数组的长度是 5 5 5,由题可知, d d d k k k的最大除数,但是 d d d不等于 k k k,则如果 k % d = 0 k\%d=0 k%d=0,那么就将下标为 d d d k k k的元素进行交换,模拟过程如下:

i i i12345
a [ i ] a[i] a[i]12345

⇓ \Darr

i i i12345
a [ i ] a[i] a[i]21345

⇓ \Darr

i i i12345
a [ i ] a[i] a[i]31245

⇓ \Darr

i i i12345
a [ i ] a[i] a[i]34215

⇓ \Darr

i i i12345
a [ i ] a[i] a[i]54213

2、代码

#include<iostream>
using namespace std;
const int N = 1e4 + 10;
int t, n;
int main() {
	scanf("%d", &t);
	while (t--) {
		int p = 1;
		scanf("%d", &n);
		while (2 * p <= n) {
			p <<= 1;
		}
		printf("%d\n", p);
	}
	return 0;
}

B. Binary Path

B. Binary Path

                                         B. Binary Path
                                  time limit per test: 1 second
                               memory limit per test: 256 megabytes
                                     input: standard input
                                     output: standard output

You are given a 2 × n 2 \times n 2×n grid filled with zeros and ones. Let the number at the intersection of the i i i-th row and the j j j-th column be a i j a_{ij} aij.

There is a grasshopper at the top-left cell ( 1 , 1 ) (1, 1) (1,1) that can only jump one cell right or downwards. It wants to reach the bottom-right cell ( 2 , n ) (2, n) (2,n). Consider the binary string of length n + 1 n+1 n+1 consisting of numbers written in cells of the path without changing their order.

Your goal is to:

  1. Find the lexicographically smallest † ^\dagger string you can attain by choosing any available path;
  2. Find the number of paths that yield this lexicographically smallest string.

† ^\dagger If two strings s s s and t t t have the same length, then s s s is lexicographically smaller than t t t if and only if in the first position where s s s and t t t differ, the string s s s has a smaller element than the corresponding element in t t t.

Input

Each test contains multiple test cases. The first line contains the number of test cases t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1t104). The description of the test cases follows.

The first line of each test case contains a single integer n n n ( 2 ≤ n ≤ 2 ⋅ 1 0 5 2 \le n \le 2 \cdot 10^5 2n2105).

The second line of each test case contains a binary string a 11 a 12 … a 1 n a_{11} a_{12} \ldots a_{1n} a11a12a1n ( a 1 i a_{1i} a1i is either 0 0 0 or 1 1 1).

The third line of each test case contains a binary string a 21 a 22 … a 2 n a_{21} a_{22} \ldots a_{2n} a21a22a2n ( a 2 i a_{2i} a2i is either 0 0 0 or 1 1 1).

It is guaranteed that the sum of n n n over all test cases does not exceed 2 ⋅ 1 0 5 2 \cdot 10^5 2105.

Output

For each test case, output two lines:

  1. The lexicographically smallest string you can attain by choosing any available path;
  2. The number of paths that yield this string.

Input
3
2
00
00
4
1101
1100
8
00100111
11101101

Output
000
2
11000
1
001001101
4

Note

In the first test case, the lexicographically smallest string is 000 \mathtt{000} 000. There are two paths that yield this string:

In the second test case, the lexicographically smallest string is 11000 \mathtt{11000} 11000. There is only one path that yields this string:

1、过程模拟

由题可知,蚂蚱只能向右或者是向下移动,并且使得二进制数的值是最小的路径,路径条数不止一条,但二进制数值是一样的。
我们可以先从第一行的最后一列和第二行的倒数第二列进行比较,设 m a x _ d o w n = n max\_down=n max_down=n m i n _ d o w n = 1 min\_down=1 min_down=1,如果第一行的最后一列是 1 1 1,第二行的倒数第二列是 0 0 0,则将第一行原本的长度减一,即 m a x _ d o w n = n − 1 max\_down=n-1 max_down=n1
再从第二行的第一列和第一行的第二列进行比较,设 m a x _ d o w n = n max\_down=n max_down=n m i n _ d o w n = 1 min\_down=1 min_down=1,如果第二行的第一列是 1 1 1,第一行的第二列是 0 0 0,则 m i n _ d o w n = 1 + 1 min\_down=1+1 min_down=1+1,根据以上步骤以此类推。

2、代码

#include<iostream>
#include<algorithm>
using namespace std;
#define orz 0
const int N = 2e5 + 10;
int t, n;
char a[4][N];
int main() {
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		for (int i = 1; i <= 2; i++) {
			scanf("\n");
			for (int j = 1; j <= n; j++) {
				scanf("%c", &a[i][j]);
			}
		}
		int max_down = n, min_down = 1;
		for (int i = n; i >= 2; i--) {
			if (a[1][i] == '1' && a[2][i - 1] == '0') {
				max_down = i - 1;
			}
		}
		for (int i = 1; i < max_down; i++) {
			if (a[1][i + 1] == '0' && a[2][i] == '1') {
				min_down = i + 1;
			}
		}
		for (int i = 1; i <= max_down; i++) {
			printf("%c", a[1][i]);
		}
		for (int i = max_down; i <= n; i++) {
			printf("%c", a[2][i]);
		}
		puts("");
		printf("%d\n", max_down - min_down + 1);
	}
	return orz;
}

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

2024年3月2日 十二生肖 今日运势

小运播报&#xff1a;2024年3月2日&#xff0c;星期六&#xff0c;农历正月廿二 &#xff08;甲辰年丙寅月乙丑日&#xff09;&#xff0c;法定节假日。 红榜生肖&#xff1a;鸡、蛇、鼠 需要注意&#xff1a;狗、马、羊 喜神方位&#xff1a;西北方 财神方位&#xff1a;东…

【刷题】位运算

消失的两个数字 消失的两个数字 “单身狗”进阶版思路 class Solution { public:vector<int> missingTwo(vector<int>& nums) {int ret 0;int n nums.size();for(int i 0; i < n; i){ret ^ (nums[i] ^ i);}ret ^ (n ^ (n 1) ^ (n 2));// 按位异或的…

基于SpringBoot的综合小区管理系统的设计与实现

文章目录 项目介绍主要功能截图&#xff1a;部分代码展示设计总结项目获取方式 &#x1f345; 作者主页&#xff1a;超级无敌暴龙战士塔塔开 &#x1f345; 简介&#xff1a;Java领域优质创作者&#x1f3c6;、 简历模板、学习资料、面试题库【关注我&#xff0c;都给你】 &…

Linux 安装k8s

官网 常见的三种安装k8s方式 1.kubeadm 2.kops&#xff1a;自动化集群制备工具 3.kubespray&#xff1a; 提供了 Ansible Playbook 下面以kubeadm安装k8s kubeadm的安装是通过使用动态链接的二进制文件完成的&#xff0c;目标系统需要提供 glibc ##使用 ss 或者 netstat 检测端…

.halo勒索病毒的最新威胁:如何恢复您的数据?

尊敬的读者&#xff1a; 随着科技的发展&#xff0c;网络安全已经成为我们日常生活中不可忽视的重要议题。其中&#xff0c;勒索病毒是当前网络安全威胁中的一大挑战&#xff0c;而“.halo”勒索病毒更是近期备受关注的恶意软件之一。本文将介绍关于“.halo”勒索病毒的背景知…

循环简介和基本运算符

根据C Primer Plus第五章进行学习 文章目录 循环简介基本运算符 1.赋值运算符&#xff1a;2.加法运算符&#xff1a;3.减法运算符&#xff1a;-2.乘法运算符&#xff1a;*总结 1.循环简介 如下代码可以体现不使用循环的局限性&#xff1a; #include<stdio.h> #define AD…

【C语言】linux内核xmit_one函数

一、中文注释 static int xmit_one(struct sk_buff *skb, struct net_device *dev,struct netdev_queue *txq, bool more) {unsigned int len;int rc;// 如果全局ptype列表或者设备特定的ptype列表不为空&#xff0c;则执行网络接口层网络层的NIT&#xff08;Network Tap&…

【C++】vector的使用及其模拟实现

这里写目录标题 一、vector的介绍及使用1. vector的介绍2. 构造函数3. 遍历方式4. 容量操作及空间增长问题5. 增删查改6. vector二维数组 二、vector的模拟实现1. 构造函数2. 迭代器和基本接口3. reserve和resize4. push_back和pop_back5. insert和erase5. 迭代器失效问题5. 浅…

docker 基础(二)

常见命令 Docker最常见的命令就是操作镜像、容器的命令&#xff0c;详见官方文档&#xff1a;https://docs.docker.com/ 数据卷 命令说明文档地址docker volume create创建数据卷docker volume createdocker volume ls创建数据卷docker volume lsdocker volume rm查看所有数…

NGINX 高频面试题及实践总结

NGINX 是一个高性能的开源 Web 服务器和反向代理服务器&#xff0c;被广泛应用于互联网架构中。在面试中&#xff0c;对 NGINX 的相关知识可能会成为考察的重点。下面我们整理了一些常见的 NGINX 面试题及答案&#xff0c;希望对大家在面试前的准备有所帮助。 ## 1. 什么是 NG…

如何系统性的学习推荐系统?

推荐一本适合推荐系统、计算广告、个性化搜索领域的从业人员阅读的书&#xff1a;《互联网大厂推荐算法实战》。快手公司算法专家10余年的实战经验总结。涵盖一线互联网公司当前采用的主流推荐算法&#xff0c;凸显可用性、实用性提供从算法基本原理&#xff0c;到技术框架再到…

python语言1

一、pytho中的注释 1.1注释的理解 程序员在代码中对代码功能解释说明的标注性文字可以提高代码的可读性注释的内容将被python解释器忽略&#xff0c;不被计算机执行 1.2注释的分类 注释分为&#xff1a;单行注释、多行注释、中文声明注释 &#xff08;1&#xff09;单行注…

java项目打包运行报异常:xxxxx-1.0-SNAPSHOT.jar中没有主清单属性

pom.xml中加入这段话即可 <build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>2.4.4</version><executions><execution><…

雨云:为你拨开云雾见青天

一、雨云品牌概览 雨云&#xff0c;这名字一听就让人联想到蓝天白云&#xff0c;清爽自然。那么&#xff0c;这个品牌是否真的如其名&#xff0c;能为我们这些在数字世界中漂泊的旅人提供一片宁静、稳定的“云”呢&#xff1f;接下来&#xff0c;让我们深入了解雨云的资质、能…

【Micropython教程】I2C的使用

文章目录 前言一、I2C的使用1.1 分析一种情况1.2 初始化I2C总线1.3 扫描可用的I2C设备1.4 向指定地址写入数据1.5 读取指定地址的数据1.6 关闭I2C总线 二、示例代码总结 前言 MicroPython 是一种精简的 Python 实现&#xff0c;旨在运行在微控制器和嵌入式系统上。在嵌入式开发…

AVL 树

AVL树的概念 二叉搜索树虽可以缩短查找的效率&#xff0c;但如果数据有序或接近有序二叉搜索树将退化为单支树&#xff0c;查找元素相当于在顺序表中搜索元素&#xff0c;效率低下。因此&#xff0c;两位俄罗斯的数学家G.M.Adelson-Velskii和E.M.Landis在1962年 发明了一种解决…

vue3的router

需求 路由组件一般放在&#xff0c;pages或views文件夹, 一般组件通常放在component文件夹 路由的2中写法 子路由 其实就是在News组件里面&#xff0c;再定义一个router-view组件 他的子组件&#xff0c;机会渲染在router-view区域 路由传参 <RouterLink :to"/news…

腾讯云最新活动_腾讯云促销优惠_代金券-腾讯云官网入口

腾讯云服务器多少钱一年&#xff1f;62元一年起&#xff0c;2核2G3M配置&#xff0c;腾讯云2核4G5M轻量应用服务器218元一年、756元3年&#xff0c;4核16G12M服务器32元1个月、312元一年&#xff0c;8核32G22M服务器115元1个月、345元3个月&#xff0c;腾讯云服务器网txyfwq.co…

xsslabs第七关

源码 <!DOCTYPE html><!--STATUS OK--><html> <head> <meta http-equiv"content-type" content"text/html;charsetutf-8"> <script> window.alert function() { confirm("完成的不错&#xff01;"…

《2023年勒索软件攻击态势报告》

获取方式&#xff1a; 链接&#xff1a;https://pan.baidu.com/s/1zd-yVsuGwJADyyGNFR_TIQ?pwd2lo0 提取码&#xff1a;2lo0
最新文章