高贵的蕾米莉亚大小姐每天需要饮用定量 B 型血的红茶以保持威严,并且要分两杯在不同时段饮用。
女仆长十六夜咲夜每天可以制作很多杯不同剂量 B 型血的红茶供蕾米莉亚大小姐饮用。
某日,你和天才妖精琪露诺偷偷潜入红魔馆被咲夜抓住,要求在今日份的红茶中挑出所有满足大小姐要求的茶杯,否则……
每个样例有三行输入,第一行输入表示茶杯个数,第二行输入表示每份茶杯里的 B 型血剂量,第三行表示大小姐今天的定量
对每一个样例,输出所有可能的搭配方案,如果有多种方案,请按每个方案的第一杯 B 型血剂量的大小升序排列。
如果无法找到任何一种满足大小姐的方案,输出"NO"(不包括引号)并换行。
7 2 4 6 1 3 5 7 7
1 6 2 5 3 4
茶杯个数不超过100000,保证茶杯里的B型血剂量两两不同。
参考 野径入桑麻 答案,改了判断顺序,ac100%
numCup = int(input())
doseB = list(map(int, input().split()))
doseNeed = int(input())
doseB.sort()
res_all = []
start = 0
end = numCup-1
while start < end:
a = doseB[start]
b = doseB[end]
if a+b == doseNeed:
res_all.append([a,b])
if a+b > doseNeed:
end -= 1
else:
start +=1
if len(res_all) == 0:
print('NO')
else:
for item in res_all:
print('%s %s'%(item[0],item[1]))
import sys
input_strs = []
for line in sys.stdin:
input_strs.append(line.strip())
cup_N = int(input_strs[0])
cup_list = []
line_1 = input_strs[1].split(" ")
for v in line_1:
if len(v) > 0:
if v[0] >= '0' and v[0] <= '9':
cup_list.append(int(v))
else:
print("Error...")
else:
print("Error......")
cup_SUM = int(input_strs[2])
flag = False
cup_list.sort()
first, second = 0, cup_N - 1
if len(cup_list) != cup_N:
print("Error1....")
# 数组中的数一定是不一样的
while first < second:
if cup_list[first] + cup_list[second] == cup_SUM:
# result.append([cup_list[first], cup_list[second]])
print(str(cup_list[first]) + " " + str(cup_list[second]))
# 针对可能重复的fisrt
while first < second and cup_list[first] == cup_list[first + 1]:
first += 1
print(str(cup_list[first]) + " " + str(cup_list[second]))
# 针对可能重复的second
while first < second and cup_list[second] == cup_list[second - 1]:
second -= 1
print(str(cup_list[first]) + " " + str(cup_list[second]))
flag = True
first += 1
second -= 1
elif cup_list[first] + cup_list[second] < cup_SUM:
first += 1
else:
second -= 1
if not flag:
print("NO")