Consider all binary strings of length m (1≤m≤60). A binary string is a string that consists of the characters 0 and 1 only. For example, 0110 is a binary string, and 012aba is not. Obviously, there are exactly 2m such strings in total.
The string s is lexicographically smaller than the string t (both have the same length m) if in the first position i from the left in which they differ, we have s[i]<t[i]. This is exactly the way strings are compared in dictionaries and in most modern programming languages when comparing them in a standard way. For example, the string 01011 is lexicographically smaller than the string 01100, because the first two characters are the same, and the third character in the first string is less than that in the second.
We remove from this set $n (1≤n≤min(2^{m−1},100))$ distinct binary strings a1,a2,…,an, each of length m. Thus, the set will have k=2m−n strings. Sort all strings of the resulting set in lexicographical ascending order (as in the dictionary).
We number all the strings after sorting from 0 to k−1. Print the string whose index is ⌊k−1⌋/2 (such an element is called median), where ⌊x⌋ is the rounding of the number down to the nearest integer.
For example, if n=3, m=3 and a=[010, 111, 001], then after removing the strings ai and sorting, the result will take the form: [000, 011, 100, 101, 110]. Thus, the desired median is 100.
Input
The first line contains an integer t (1≤t≤1000) — the number of test cases. Then, t test cases follow.
The first line of each test case contains integers $n (1≤n≤min(2^{m−1},100))$ and m (1≤m≤60), where n is the number of strings to remove, and m is the length of binary strings. The next n lines contain a1,a2,…,an — distinct binary strings of length m.
The total length of all given binary strings in all test cases in one test does not exceed $10^5$.
Output
Print t answers to the test cases. For each test case, print a string of length m — the median of the sorted sequence of remaining strings in the corresponding test case.
voidsolve(){ int n, m; cin >> n >> m; ll a[n]; string s; ll ans = ((1LL << m) - n - 1) / 2; for (int i = 0; i < n; i++) { cin >> s; a[i] = bitset<64>(s).to_ullong(); } sort(a, a + n); for (auto i:a) ans += (i <= ans); cout << bitset<64>(ans).to_string().substr(64 - m) << endl; }
intmain(){ int t; cin >> t; while (t--) solve(); }
usingnamespace std; typedeflonglong ll; ll mod = 1e9 + 7, n, K, A, B, m, mod1 = 1e9 + 6;
ll power(ll a, ll b){ return b ? power(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
structmat { ll m[2][2]; };
mat mul(mat a, mat b){ mat c; memset(c.m, 0, sizeof(c.m)); for (int i = 0; i < n; i++) { for (int k = 0; k < n; k++) { if (a.m[i][k] == 0) continue; for (int j = 0; j < n; j++) { c.m[i][j] = (c.m[i][j] + a.m[i][k] * b.m[k][j]) % mod1; if (c.m[i][j] < 0) c.m[i][j] += mod1; } } } return c; }
mat mat_pow(mat a, int k){ mat ans; ans.m[0][0] = 1, ans.m[1][0] = 1; ans.m[0][1] = ans.m[1][1] = 0; while (k > 0) { if (k & 1) ans = mul(a, ans); a = mul(a, a); k >>= 1; } return ans; }
intmain(){ n = 2; cin >> A >> B >> m >> K; mat a; a.m[0][0] = A, a.m[0][1] = B; a.m[1][0] = 1, a.m[1][1] = 0; if (K <= 2) cout << m; else { mat ans = mat_pow(a, K - 2); ll u = ans.m[0][0]; cout << power(m, u); } return0; }
intmain(){ int n, k; vector<int> v; set<int> s; cin >> n >> k; if (n < 6 && k == n / 2) { cout << "-1"; return0; } for (int i = 2; i <= n; i += 2) if (i != 6) v.push_back(i); v.push_back(6); v.push_back(3); for (int i = 0; i <= k; i++) cout << v[i] << " ", s.insert(v[i]); for (int i = 1; i <= n; i++) if (!s.count(i)) cout << i << " "; return0; }
classSolution { public: boolcheck(longlong x, longlong y, longlong z, longlong n){ longlong num1 = y, num2 = n - y - 1; longlong sum1 = 0, sum2 = 0; if (num1 >= x - 1) { sum1 = (x - 1) * x / 2 + num1 - (x - 1); } else { sum1 = num1 * (x - num1 + x - 1) / 2; } if (num2 >= x - 1) { sum2 = (x - 1) * x / 2 + num2 - (x - 1); } else { sum2 = num2 * (x - num2 + x - 1) / 2; } return (sum1 + sum2 + x <= z); }
intmaxValue(int n, int index, int maxSum){ int l = 1, r = maxSum; while (l <= r) { int mid = l + r >> 1; if (check(mid, index, maxSum, n)) l = mid + 1; else r = mid - 1; } return r; } };
You are given a string $s{}$ of $n{}$ lowercase letters. You have to delete exactly two letters from $s{}$, determine whether the string can become a palindrome after the change. Definition of palindrome: If a string $s{}$ of $n{}$ lowercase letters is a palindrome, then for each $s_i(1\leq i\leq n),s_i=s{n-i+1}$ . For example, “ababa” and “abba” are palindromes, but “abab” not.
输入描述:
The first line contains an integer $t(1\leq t\leq10^3)$ — the number of test cases. For each test case, the first line contains an integer $n(3\leq n\leq 2!\cdot!10^3)$ representing the length of $s{}$, the second line contains a string of length $n{}$. It is guaranteed that the sum of $n{}$ for all test cases does not exceed $10^4{}$.
输出描述:
If it is possible to change the string into a palindrome after deleting two letters from $s_{}$, please output “Yes”, otherwise output “No”.
当 A 的子数组 A[i], A[i+1], …, A[j] 满足下列条件时,我们称其为湍流子数组:
若 i <= k < j,当 k 为奇数时, A[k] > A[k+1],且当 k 为偶数时,A[k] < A[k+1]; 或 若 i <= k < j,当 k 为偶数时,A[k] > A[k+1] ,且当 k 为奇数时, A[k] < A[k+1]。 也就是说,如果比较符号在子数组中的每个相邻元素对之间翻转,则该子数组是湍流子数组。
x = input() m = int(input()) iflen(x) == 1: ifint(x) <= m: print(1) else: print(0) sys.exit(0) len = len(x)
defcheck(n): sum = 0 for j inrange(0, len): ss = 1 for k inrange(0, len - j - 1): ss *= n if ss > m: return1 sum += ss * (ord(x[j]) - ord('0')) ifsum > m: return1 return0
d = 0 ans = 0 for i in x: d = max(d, ord(i) - ord('0') + 1)
l = d r = 10 ** 18 + 1 while l <= r: mid = (l + r) // 2 if check(mid): r = mid - 1 else: l = mid + 1 print(r - d + 1)