import random
def random(n, m):
return random.randint(0, n - 1) + m
T = int(input())
for i in range(T):
a, b = map(int, input().split())
print(b - a, a)
import random
def cpi(arr, start, end):
return random.randint(start, end)
def qsort(arr, start, end):
if start < end:
ind_piv = cpi(arr, start, end)
arr[ind_piv], arr[end] = arr[end], arr[ind_piv]
ind_par = partition(arr, start, end)
qsort(arr, start, ind_par - 1)
qsort(arr, ind_par + 1, end)
def partition(arr, start, end):
piv = arr[end]
i = start - 1
for j in range(start, end):
if arr[j] <= piv:
i += 1
arr[i], arr[j] = arr[j], arr[i]
arr[i + 1], arr[end] = arr[end], arr[i + 1]
return i + 1
while True:
arr = list(map(int, input().split()))
arr = arr[1:]
qsort(arr, 0, len(arr) - 1)
print(" ".join(map(str, arr)))
while True:
import random
def partition(arr, p, q):
x = arr[p]
i = p
for j in range(p + 1, q + 1):
if arr[j] <= x:
i += 1
arr[i], arr[j] = arr[j], arr[i]
arr[i], arr[p] = arr[p], arr[i]
return i
def quickselect(arr, s, t, k):
if s == t:
return arr[s]
i = partition(arr, s, t)
j = i - s + 1
if k == j:
return arr[i]
elif k < j:
return quickselect(arr, s, i - 1, k)
else:
return quickselect(arr, i + 1, t, k - j)
def randomizedselect(arr, s, t, k):
if s == t:
return arr[s]
i = randomizedpartition(arr, s, t)
j = i - s + 1
if k == j:
return arr[i]
elif k < j:
return randomizedselect(arr, s, i - 1, k)
else:
return randomizedselect(arr, i + 1, t, k - j)
def rand(p, q):
return random.randint(p, q)
def randomizedpartition(arr, p, q):
r = rand(p, q)
arr[p], arr[r] = arr[r], arr[p]
return partition(arr, p, q)
arr = list(map(int, input().split()))
k = int(input())
print(randomizedselect(arr, 0, len(arr) - 1, k))
#include <iostream>
#include <vector>
#include <cstdlib>
int partition(std::vector<int>& arr, int p, int q) {
int x = arr[p];
int i = p;
for (int j = p + 1; j <= q; ++j) {
if (arr[j] <= x) {
i++;
std::swap(arr[i], arr[j]);
}
}
std::swap(arr[i], arr[p]);
return i;
}
int quickselect(std::vector<int>& arr, int s, int t, int k) {
if (s == t) {
return arr[s];
}
int i = partition(arr, s, t);
int j = i - s + 1;
if (k == j) {
return arr[i];
}
else if (k < j) {
return quickselect(arr, s, i - 1, k);
}
else {
return quickselect(arr, i + 1, t, k - j);
}
}
int rand(int p, int q) {
return rand() % (q - p + 1) + p;
}
int randomizedpartition(std::vector<int>& arr, int p, int q) {
int r = rand(p, q);
std::swap(arr[p], arr[r]);
return partition(arr, p, q);
}
int randomizedselect(std::vector<int>& arr, int s, int t, int k) {
if (s == t) {
return arr[s];
}
int i = randomizedpartition(arr, s, t);
int j = i - s + 1;
if (k == j) {
return arr[i];
}
else if (k < j) {
return randomizedselect(arr, s, i - 1, k);
}
else {
return randomizedselect(arr, i + 1, t, k - j);
}
}
int main() {
int n;
while (std::cin >> n) {
std::vector<int> arr(n);
for (int i = 0; i < n; ++i) {
std::cin >> arr[i];
}
if (n % 2 != 0) {
int res1 = randomizedselect(arr, 0, n - 1, (n - 1) / 2 + 1);
std::cout << res1 << std::endl;
}
else {
int res1 = randomizedselect(arr, 0, n - 1, (n - 1) / 2 + 1);
int res2 = randomizedselect(arr, 0, n - 1, (n - 1) / 2 + 2);
std::cout << std::fixed;
std::cout.precision(3);
std::cout << (static_cast<double>(res2 + res1) / 2.0) << std::endl;
}
}
return 0;
}
python过不了
while True:
x1 = list(map(int, input().split()))
x2 = list(map(int, input().split()))
arr1 = x1[1:]
arr2 = x2[1:]
p, q = 0, 0
sorted = []
while p < len(arr1) or q < len(arr2):
if p == len(arr1):
sorted.append(arr2[q])
q += 1
elif q == len(arr2):
sorted.append(arr1[p])
p += 1
elif arr1[p] < arr2[q]:
sorted.append(arr1[p])
p += 1
else:
sorted.append(arr2[q])
q += 1
arr1[:] = sorted
print(*arr1)
print()
while True:
def merge(left, right):
result = []
i = j = 0
while i < len(left) and j < len(right):
if left[i] < right[j]:
result.append(left[i])
i += 1
else:
result.append(right[j])
j += 1
result.extend(left[i:])
result.extend(right[j:])
return result
def merge_sort(arr):
if len(arr) <= 1:
return arr
mid = len(arr) // 2
left = arr[:mid]
right = arr[mid:]
left = merge_sort(left)
right = merge_sort(right)
return merge(left, right)
arr = list(map(int, input().split()))[1:]
sorted_arr = merge_sort(arr)
print(*sorted_arr)
s = input()
len_s = len(s)
s = '*' + s
ans = 0
l = 0
r = 0
dp = [0] * (len_s + 10)
for i in range(1, len_s + 1):
if s[i] in ['[', '(', '<', '{']:
continue
if ((s[i] == ']' and s[i - 1 - dp[i - 1]] == '[') or
(s[i] == ')' and s[i - 1 - dp[i - 1]] == '(') or
(s[i] == '}' and s[i - 1 - dp[i - 1]] == '{') or
(s[i] == '>' and s[i - 1 - dp[i - 1]] == '<')):
dp[i] = dp[i - 1] + 2 + dp[i - 2 - dp[i - 1]]
if ans < dp[i]:
ans = dp[i]
print(ans)
shu = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"]
unit = ['', '拾', '佰', '仟']
da_unit = ['万', '亿']
xs_unit = ['角', '分']
law = '人民币'
tial = '元'
while True:
n = str(float(input().strip()))
exit = 0
if float(n) == 0.0:
print('零元整')
exit = 1
if exit == 0:
n = n + '00'
div = n.find('.')
div_xs = n[div + 1:div + 3]
if div_xs[0] != '0' and div_xs[1] != '0':
xs = shu[int(div_xs[0])] + xs_unit[0] + shu[int(div_xs[1])] + xs_unit[1]
elif div_xs[0] != '0' and div_xs[1] == '0':
xs = shu[int(div_xs[0])] + xs_unit[0]
elif div_xs[0] == '0' and div_xs[1] != '0':
xs = shu[int(div_xs[1])] + xs_unit[1]
else:
xs = '整'
flag = -1
n_zs = n[:div]
if int(n_zs) != 0:
zs1 = n_zs[::-1][:4]
zs2 = n_zs[::-1][4:8]
zs3 = n_zs[::-1][8:12]
zs4 = n_zs[::-1][12:16]
zs = ''
if len(n_zs) >= 1:
if int(zs1) != 0:
zs1 = zs1.replace('000', '0**').replace('00', '0*')
for i in range(len(zs1)):
if i == 0 and zs1[0] == '0':
zs += ''
elif zs1[i] != '*' and zs1[i] != '0':
zs += unit[i] + shu[int(zs1[i])]
elif zs1[i] != '*' and zs1[i] == '0':
zs += shu[int(zs1[i])]
else:
if len(n_zs) <= 4:
zs += '零'
else:
zs += ''
if len(n_zs) >= 5:
if int(zs2) != 0:
zs += da_unit[0]
zs2 = zs2.replace('000', '0**').replace('00', '0*')
for i in range(len(zs2)):
if i == 0 and zs2[0] == '0':
zs += ''
elif zs2[i] != '*' and zs2[i] != '0':
zs += unit[i] + shu[int(zs2[i])]
elif zs2[i] != '*' and zs2[i] == '0':
zs += shu[int(zs2[i])]
else:
if 8 >= len(n_zs) > 4:
zs += '零'
if len(n_zs) > 8:
zs += ''
if len(n_zs) >= 9:
if len(n_zs) > 12:
zs += da_unit[1]
if int(zs3) != 0:
zs3 = zs3.replace('000', '0**').replace('00', '0*')
for i in range(len(zs3)):
if i == 0 and zs3[0] == '0':
zs += ''
elif zs3[i] != '*' and zs3[i] != '0':
zs += unit[i] + shu[int(zs3[i])]
elif zs3[i] != '*' and zs3[i] == '0':
zs += shu[int(zs3[i])]
else:
if 12 >= len(n_zs) > 8:
zs += '零'
if len(n_zs) > 12:
zs += ''
if len(n_zs) >= 13:
if int(zs4) != 0:
zs += da_unit[0]
zs4 = zs4.replace('000', '0**').replace('00', '0*')
for i in range(len(zs4)):
if i == 0 and zs4[0] == '0':
zs += ''
elif zs4[i] != '*' and zs4[i] != '0':
zs += unit[i] + shu[int(zs4[i])]
elif zs4[i] != '*' and zs4[i] == '0':
zs += shu[int(zs4[i])]
else:
if 16 >= len(n_zs) > 12:
zs += ''
zs = zs[::-1] + tial
else:
zs = ''
ans = law + zs + xs
if ans[3] == '壹' and ans[4] == '拾':
ans = ans[:3] + ans[4:]
print(ans)
有个示例一直过不了