NC212614. BrokenPad
描述
输入描述
There are multiple test cases. The first line of input contains an integer T (1 ≤ T ≤ 10), indicating the number of test cases. For each test case:
The first line contains a string a (1 ≤ |a| ≤ ), indicating the current state of the card.
The second line contains a string b (|b| = |a|), indicating the state required by ZH.
输出描述
For each test case, print one line contains the minimum number of integers indicating the position ZH should tap in non-decreasing order.
Please note that number 0 is indicating the blank space, and it's guaranteed that the solution of all the test cases is unique.
示例1
输入:
2 10110 10000 110101 000000
输出:
3 5 0
说明:
For the first sample, a is "10110", and b is "10000", then ZH needs first to tap the position 3 (based on 1) to make the state become "10001", and then tap the position 5 to make the state become "10000", so you should tell him 3 and 5.Python3(3.9) 解法, 执行用时: 795ms, 内存消耗: 6956K, 提交时间: 2021-03-08 16:26:13
for _ in range(int(input())): a=input() b=input() if '1' not in b: print(0) else: c=bin(int(a,2)^int(b,2))[2:] start=1+len(a)-len(c) t=0 wz=[start] for i in range(len(c)): if c[i]==str(t): wz.append(i+start) t=1-t wz2=[0] start2=1 t2=1 for i in range(len(b)): if b[i]==str(t2): wz2.append(i+start2) t2=1-t2 if len(wz)>len(wz2): print(*wz2) else: print(*wz)
C++11(clang++ 3.9) 解法, 执行用时: 67ms, 内存消耗: 1812K, 提交时间: 2020-09-27 11:09:05
#include<bits/stdc++.h> using namespace std; int _,n,a[100005],b[100005]; string s1,s2; int main(){ int i; for (scanf("%d",&_);_;_--){ cin>>s1>>s2; n=s1.length(); a[0]=b[1]=0; b[0]=1; for (i=0;i<n;i++) if ((s1[i]!=s2[i])^(a[0]&1)) a[++a[0]]=i+1; for (i=0;i<n;i++) if ((s2[i]=='0')^(b[0]&1)) b[++b[0]]=i+1; if (a[0]<b[0]) for (i=1;i<=a[0];i++) printf("%d ",a[i]); else for (i=1;i<=b[0];i++) printf("%d ",b[i]); printf("\n"); } return 0; }