文章目录
前言
暂8
202009-2风险人群筛查
n, k, t, x_l, y_d, x_r , y_u = list(map(int, input().split()))
pass_by = 0
stay = 0
def judge(x,y,x_l, y_d, x_r, y_u):
return x_l <= x <= x_r and y_d <= y <= y_u
for i in range(n):
dot_lst = list(map(int, input().split()))
tmp_pass = 0
tmp_stay_cot = 0
tmp_stay = 0
for j in range(t):
x = dot_lst[2*j]
y = dot_lst[2*j+1]
is_in = judge(x,y,x_l, y_d, x_r, y_u)
if is_in:
tmp_pass = 1
tmp_stay_cot += 1
if tmp_stay_cot>=k:
tmp_stay = 1
break
else:
tmp_stay_cot = 0
pass_by += tmp_pass
stay += tmp_stay
print(pass_by)
print(stay, end="")
202006-2稀疏向量
n, a, b = list(map(int, input().split()))
a_dict = {
}
for i in range(a):
index,value = list(map(int, input().split()))
a_dict[index] = value
ans = 0
for j in range(b):
index,value = list(map(int, input().split()))
if index in a_dict:
ans += value * a_dict[index]
del a_dict[index]
print(ans)
201912-2回收站选址
"""
测试点9、10: (2*10**9)**2/8/1024/1024 = ...
"""
ans_lst = [0,0,0,0,0]
dot_dict = {
}
judge1_lst = [(-1,0),(0,1),(1,0),(0,-1)]
judge2_lst = [(-1,1),(1,1),(1,-1),(-1,-1)]
n = int(input())
def check(dot_dict, x,y):
# left up right down
for i in judge1_lst:
new_x,new_y = x+i[0], y+i[1]
if (new_x,new_y) in dot_dict:
dot_dict[(new_x,new_y)][0] += 1
dot_dict[(x, y)][0] += 1
for i in judge2_lst:
new_x, new_y = x + i[0], y + i[1]
if (new_x, new_y) in dot_dict:
dot_dict[(new_x, new_y)][1] += 1
dot_dict[(x, y)][1] += 1
return dot_dict
for i in range(n):
x,y = list(map(int, input().split()))
dot_dict[(x,y)] = [0,0]
dot_dict = check(dot_dict, x,y)
for v in dot_dict.values():
if v[0] == 4:
ans_lst[v[1]] += 1
print(ans_lst[0])
print(ans_lst[1])
print(ans_lst[2])
print(ans_lst[3])
print(ans_lst[4], end="")
201909-2小明种苹果(续)
T = D = E = 0
N = int(input())
have_drop = []
for i in range(N):
tmp_D = 0
input_lst = list(map(int, input().split()))
apple_num = input_lst[1]
for j in input_lst[2:]:
if j <= 0:
apple_num += j
else:
if j != apple_num:
tmp_D = 1
apple_num = j
T += apple_num
have_drop.append(tmp_D)
for idx, i in enumerate(have_drop):
if i == 1:
D += 1
if idx == 0:
pre = N-1
suc = idx+1
elif idx == N-1:
pre = idx - 1
suc = 0
else:
pre = idx - 1
suc = idx + 1
if have_drop[pre] * have_drop[suc] == 1:
E += 1
print(T,end=" ")
print(D,end=" ")
print(E,end="")
201903-2二十四点
"""
加减法:两个栈
1.数字:直接入栈
2.符号:
如果符号栈的第一个符号的优先级比当前符号低,则入栈
否则,取出栈中所有优先级较高的,做运算
最后把栈中剩下的,都计算完,
"""
def operate_(num1,num2,op):
if op == "+":
ans = num1 + num2
elif op == "-":
ans = num1 - num2
elif op == "x":
ans = num1 * num2
else:
ans = num1 // num2
return ans
n = int(input())
prior_dict = {
"+":1,"-":1,"x":2,"/":2}
for i in range(n):
num_stack = []
op_stack = []
stringg = input()
for j in stringg:
if j.isdigit():
num_stack.append(int(j))
else: # 符号
if len(op_stack) == 0 or prior_dict[op_stack[-1]] < prior_dict[j]:
op_stack.append(j)
else:
while len(op_stack) != 0 and prior_dict[op_stack[-1]] >= prior_dict[j]:
p_j = op_stack.pop()
num2 = num_stack.pop()
num1 = num_stack.pop()
tmp_ans = operate_(num1,num2,p_j)
num_stack.append(tmp_ans)
op_stack.append(j)
while len(op_stack) != 0:
op = op_stack.pop()
num2 = num_stack.pop()
num1 = num_stack.pop()
tmp_ans = operate_(num1,num2,op)
num_stack.append(tmp_ans)
if num_stack[0] == 24:
print("Yes")
else:
print("No")
201809-1卖菜
n = int(input())
price_lst = list(map(int, input().split()))
for idx, price in enumerate(price_lst):
if idx == 0:
print((price + price_lst[idx+1])//2, end=" ")
elif idx == len(price_lst)-1:
print((price + price_lst[idx-1])//2,end="")
else:
print((price_lst[idx-1]+price + price_lst[idx+1])//3,end=" ")
201803-2碰撞的小球
ball_lst = []
n, L, t = list(map(int, input().split()))
init_place_lst = list(map(int, input().split()))
for init_place in init_place_lst:
ball_lst.append([init_place, 1])
del init_place_lst
for time in range(t):
tmp_dict = {
}
collide_ball = None
for ball_idx,ball_place in enumerate(ball_lst):
ball_lst[ball_idx][0] = ball_lst[ball_idx][0] + ball_lst[ball_idx][1]
# turn direction
if ball_lst[ball_idx][0] == 0 or ball_lst[ball_idx][0] == L:
ball_lst[ball_idx][1] = 1 if ball_lst[ball_idx][1] == -1 else -1
if ball_lst[ball_idx][0] not in tmp_dict:
tmp_dict[ball_lst[ball_idx][0]] = [ball_idx]
else:
# find collided_ball
tmp_dict[ball_lst[ball_idx][0]].append(ball_idx)
ball_idx1,ball_idx2 = tmp_dict[ball_lst[ball_idx][0]]
ball_lst[ball_idx1][1] = 1 if ball_lst[ball_idx1][1] == -1 else -1
ball_lst[ball_idx2][1] = 1 if ball_lst[ball_idx2][1] == -1 else -1
for idx, (place, direction) in enumerate(ball_lst):
if idx != len(ball_lst) -1:
print(place, end=" ")
else:
print(place, end="")