当前位置:网站首页>蓝桥杯 决赛 异或变换 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));
}
}
边栏推荐
- [PHP] PHP interface inheritance and interface multi inheritance principle and implementation method
- 在哪个期货公司开期货户最安全?
- 全网“追杀”钟薛高
- 谈谈 SAP 系统的权限管控和事务记录功能的实现
- The latest interview experience of Android manufacturers in 2022, Android view+handler+binder
- Binary search tree (features)
- HAVE FUN | “飞船计划”活动最新进展
- 水平垂直居中 方法 和兼容
- Personal notes of graphics (1)
- 3000 words speak through HTTP cache
猜你喜欢

预售17.9万,恒驰5能不能火?产品力在线,就看怎么卖
最新高频Android面试题目分享,带你一起探究Android事件分发机制

Pycharm terminal enables virtual environment

Interface oriented programming

记录Servlet学习时的一次乱码

Prediction - Grey Prediction

Vs2019 configuration matrix library eigen
ByteDance Android gold, silver and four analysis, Android interview question app

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

字节跳动Android面试,知识点总结+面试题解析
随机推荐
Vs2019 configuration matrix library eigen
水平垂直居中 方法 和兼容
LocalStorage和SessionStorage
The latest interview experience of Android manufacturers in 2022, Android view+handler+binder
【DesignMode】模板方法模式(Template method pattern)
【DesignMode】享元模式(Flyweight Pattern)
使用JSON.stringify()去实现深拷贝,要小心哦,可能有巨坑
spark调优(三):持久化减少二次查询
Sort out several important Android knowledge and advanced Android development interview questions
LeetCode 1186. 删除一次得到子数组最大和 每日一题
射线与OBB相交检测
AutoLISP series (3): function function 3
Binary search tree (basic operation)
Horizontal and vertical centering method and compatibility
值得一看,面试考点与面试技巧
华东师大团队提出,具有DNA调控电路的卷积神经网络的系统分子实现
预测——灰色预测
Master this promotion path and share interview materials
Cesium(3):ThirdParty/zip. js
"The" "PIP" "entry cannot be recognized as the name of a cmdlet, function, script file, or runnable program."