当前位置:网站首页>蓝桥杯 决赛 异或变换 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));
}
}
边栏推荐
- 直接上干货,100%好评
- Advanced C language -- function pointer
- Common training data set formats for target tracking
- LocalStorage和SessionStorage
- [designmode] facade patterns
- Temperature sensor chip used in temperature detector
- 如何快速检查钢网开口面积比是否符合 IPC7525
- Tidb cannot start after modifying the configuration file
- Cesium (4): the reason why gltf model is very dark after loading
- Prometheus API deletes all data of a specified job
猜你喜欢
随机推荐
Personal notes of graphics (2)
Build an all in one application development platform, light flow, and establish a code free industry benchmark
Talk about the realization of authority control and transaction record function of SAP system
Opencv configuration 2019vs
[hcsd celebrity live broadcast] teach the interview tips of big companies in person - brief notes
Detailed explanation of several ideas for implementing timed tasks in PHP
Opencv personal notes
预售17.9万,恒驰5能不能火?产品力在线,就看怎么卖
Master this set of refined Android advanced interview questions analysis, oppoandroid interview questions
AutoLISP series (1): function function 1
os、sys、random标准库主要功能
【PHP】PHP接口继承及接口多继承原理与实现方法
Laravel5.1 Routing - routing packets
DAPP defi NFT LP single and dual currency liquidity mining system development details and source code
二叉搜索树(基操篇)
Tragedy caused by deleting the console statement
Three. JS series (1): API structure diagram-1
Personal notes of graphics (4)
three. JS create cool snow effect
As an Android Developer programmer, Android advanced interview





![[medical segmentation] attention Unet](/img/f4/cf5b8fe543a19a5554897a09b26e68.png)



