当前位置:网站首页>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));
}
}
边栏推荐
- 偶然升职的内心独白
- QT视频传输
- Horizontal and vertical centering method and compatibility
- LeetCode 1477. Find two subarrays with sum as the target value and no overlap
- LeetCode 1049. 最后一块石头的重量 II 每日一题
- LeetCode 300. 最长递增子序列 每日一题
- 【医学分割】attention-unet
- LeetCode 1654. The minimum number of jumps to get home one question per day
- Record the migration process of a project
- Personal notes of graphics (1)
猜你喜欢
随机推荐
【Seaborn】组合图表:PairPlot和JointPlot
Build an all in one application development platform, light flow, and establish a code free industry benchmark
爬虫(17) - 面试(2) | 爬虫面试题库
QT视频传输
作为Android开发程序员,android高级面试
LeetCode 1981. 最小化目标值与所选元素的差 每日一题
LeetCode 213. Home raiding II daily question
skimage学习(3)——Gamma 和 log对比度调整、直方图均衡、为灰度图像着色
Cesium(3):ThirdParty/zip. js
谈谈 SAP 系统的权限管控和事务记录功能的实现
Master this set of refined Android advanced interview questions analysis, oppoandroid interview questions
Seaborn数据可视化
Personal notes of graphics (1)
低代码(lowcode)帮助运输公司增强供应链管理的4种方式
Prediction - Grey Prediction
二叉搜索树(特性篇)
ATM系统
Three. JS series (3): porting shaders in shadertoy
Personal notes of graphics (2)
LeetCode 152. 乘积最大子数组 每日一题