当前位置:网站首页>Blue Bridge Cup final XOR conversion 100 points
Blue Bridge Cup final XOR conversion 100 points
2022-07-07 16:59:00 【@Little safflower】
Problem description
The time limit : 3.0s Memory limit : 512.0MB The total score of this question :20 branch
Problem description
Xiaolan has one 01 strand s = s1s2s3 ⋅ ⋅ ⋅ sn.
Every moment in the future , Xiao Lan wants to be right about this 01 The string is transformed once . The rules for each transformation are the same .
about 01 strand s = s1s2s3 ⋅ ⋅ ⋅ sn, Transformed 01 strand s' = s'1s'2s'3 ⋅ ⋅ ⋅ s'n by :
s'1=s1;
s'i=si-1⊕si.
among a ⊕ b Represents the XOR of two binary systems , When a and b The result is 0 , When a and b
At different times, the result is 1.
Excuse me, , after t After several transformations 01 What is string ?Input format
The first line of input contains two integers n,t, respectively 01 The length of the string and the number of transformations .
The second line contains a length of n Of 01 strand .Output format
The output line contains a 01 strand , Is the transformed string .
The test sample 1
Input:
5 3
10110Output:
11010Explanation:
When the initial for 10110, Transformation 1 After three times, it becomes 11101, Transformation 2 After three times, it becomes 10011, Transformation 3 After three times, it becomes 11010.Evaluate use case size and conventions
about 40% The evaluation case of ,1 ≤ n ≤ 100 , 1 ≤ t ≤ 1000.
about 80% The evaluation case of ,1 ≤ n ≤ 1000 , 1 ≤ t ≤ 10^9.
For all profiling use cases ,1 ≤ n ≤ 10000 , 1 ≤ t ≤ 10^18.
Java
import java.util.Scanner;
public class XOR transformation {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int t = scanner.nextInt();
int circle = 1;
// The final rule is when greater than or equal to n One of the 2 In the case of an integer power of , There must be a cycle .
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));
}
}
边栏推荐
- skimage学习(2)——RGB转灰度、RGB 转 HSV、直方图匹配
- 网关Gateway的介绍与使用
- Introduction and use of gateway
- 爬虫(17) - 面试(2) | 爬虫面试题库
- 值得一看,面试考点与面试技巧
- logback. XML configure logs of different levels and set color output
- 【DesignMode】外观模式 (facade patterns)
- LeetCode 1049. Weight of the last stone II daily question
- AutoLISP series (2): function function 2
- LeetCode 1626. The best team without contradiction
猜你喜欢
[Android -- data storage] use SQLite to store data
Pycharm IDE下载
QML beginner
面向接口编程
Sort out several important Android knowledge and advanced Android development interview questions
【MySql进阶】索引详解(一):索引数据页结构
Opencv configuration 2019vs
Temperature sensor chip used in temperature detector
Arduino 控制的双足机器人
最新2022年Android大厂面试经验,安卓View+Handler+Binder
随机推荐
Cesium(3):ThirdParty/zip. js
LeetCode 1654. 到家的最少跳跃次数 每日一题
Direct dry goods, 100% praise
LeetCode 120. Triangle minimum path and daily question
[designmode] facade patterns
logback. XML configure logs of different levels and set color output
【DesignMode】模板方法模式(Template method pattern)
编程模式-表驱动编程
一文读懂数仓中的pg_stat
Record the migration process of a project
Opencv personal notes
模块六
AutoLISP series (1): function function 1
time标准库
数据中台落地实施之法
射线与OBB相交检测
Pycharm IDE下载
C语言进阶——函数指针
skimage学习(1)
QT video transmission