当前位置:网站首页>蓝桥杯 决赛 异或变换 100分
蓝桥杯 决赛 异或变换 100分
2022-07-07 15:32:00 【@小红花】
问题描述
时间限制: 3.0s 内存限制: 512.0MB 本题总分:20 分
问题描述
小蓝有一个 01 串 s = s1s2s3 ⋅ ⋅ ⋅ sn。
以后每个时刻,小蓝要对这个 01 串进行一次变换。每次变换的规则相同。
对于 01 串 s = s1s2s3 ⋅ ⋅ ⋅ sn,变换后的 01 串s' = s'1s'2s'3 ⋅ ⋅ ⋅ s'n为:
s'1=s1;
s'i=si-1⊕si。
其中 a ⊕ b 表示两个二进制的异或,当 a 和 b 相同时结果为 0 ,当 a 和 b
不同时结果为 1。
请问,经过 t 次变换后的 01 串是什么?输入格式
输入的第一行包含两个整数 n,t,分别表示 01 串的长度和变换的次数。
第二行包含一个长度为 n 的 01 串。输出格式
输出一行包含一个 01 串,为变换后的串。
测试样例1
Input:
5 3
10110Output:
11010Explanation:
初始时为 10110,变换 1 次后变为 11101,变换 2 次后变为 10011,变换 3 次后变为 11010。评测用例规模与约定
对于 40% 的评测用例,1 ≤ n ≤ 100 , 1 ≤ t ≤ 1000。
对于 80% 的评测用例,1 ≤ n ≤ 1000 , 1 ≤ t ≤ 10^9。
对于所有评测用例,1 ≤ n ≤ 10000 , 1 ≤ t ≤ 10^18。
Java
import java.util.Scanner;
public class 异或变换 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int t = scanner.nextInt();
int circle = 1;
//最终的规律是当大于等于n的一个2的整数次幂情况下,必定存在循环。
while(circle < n) {
circle <<= 1;
}
t %= circle;
char[] arr = scanner.next().toCharArray();
for(int i = 0;i < t;i++) {
for(int j = n - 1;j > 0;j--) {
if(arr[j] == arr[j - 1]) {
arr[j] = '0';
}else {
arr[j] = '1';
}
}
//System.out.println(new String(arr));
}
System.out.println(new String(arr));
}
}
边栏推荐
- JS中null NaN undefined这三个值有什么区别
- Laravel post shows an exception when submitting data
- Interface oriented programming
- 删除 console 语句引发的惨案
- Tidb cannot start after modifying the configuration file
- LeetCode 1981. 最小化目标值与所选元素的差 每日一题
- Lowcode: four ways to help transportation companies enhance supply chain management
- 字节跳动Android金三银四解析,android面试题app
- 打造All-in-One应用开发平台,轻流树立无代码行业标杆
- DAPP defi NFT LP single and dual currency liquidity mining system development details and source code
猜你喜欢

Master this promotion path and share interview materials
直接上干货,100%好评

爬虫(17) - 面试(2) | 爬虫面试题库

Advanced C language -- function pointer

【C 语言】 题集 of Ⅹ
3000 words speak through HTTP cache

Spark Tuning (III): persistence reduces secondary queries

掌握这套精编Android高级面试题解析,oppoAndroid面试题

Cesium(3):ThirdParty/zip. js

低代码(lowcode)帮助运输公司增强供应链管理的4种方式
随机推荐
time标准库
logback. XML configure logs of different levels and set color output
[designmode] flyweight pattern
最新高频Android面试题目分享,带你一起探究Android事件分发机制
Talk about the realization of authority control and transaction record function of SAP system
面试题 01.02. 判定是否互为字符重排-辅助数组算法
C语言进阶——函数指针
运算符
pycharm 终端部启用虚拟环境
LocalStorage和SessionStorage
Personal notes of graphics (2)
Laravel post shows an exception when submitting data
Sqlserver2014+: create indexes while creating tables
Imitate the choice of enterprise wechat conference room
QT中自定义控件的创建到封装到工具栏过程(二):自定义控件封装到工具栏
记录Servlet学习时的一次乱码
【DesignMode】代理模式(proxy pattern)
Opportunity interview experience summary
OpenGL personal notes
Tragedy caused by deleting the console statement