人生第一次ac三题居然是内推坑我的网易,内附代码
斑马,翻牌,倒香槟。内推时面的人工智能事业部没hc挂了,这次换杭研同一个岗,希望有个好结果把。
斑马:纯模拟
import sys
if __name__ == '__main__':
str = sys.stdin.readline().strip()
max_res, temp_res = 0, 1
for i in range(1, len(str)):
if str[i] == str[i - 1]:
if str[0] != str[-1]:
str = str[:i][::-1] + str[i:][::-1]
else:
max_res = max(max_res, temp_res)
temp_res = 1
continue
temp_res += 1
max_res = max(max_res, temp_res)
print(max_res)
if __name__ == '__main__':
str = sys.stdin.readline().strip()
max_res, temp_res = 0, 1
for i in range(1, len(str)):
if str[i] == str[i - 1]:
if str[0] != str[-1]:
str = str[:i][::-1] + str[i:][::-1]
else:
max_res = max(max_res, temp_res)
temp_res = 1
continue
temp_res += 1
max_res = max(max_res, temp_res)
print(max_res)
翻牌:找规律
def get_negative_block(n, m):
if n == 1 and m == 1:
return 1
if n == 2 or m == 2:
return 0
if n == 1 and m > 2:
return m - 2
if n > 2 and m == 1:
return n - 2
return (n - 2) * (m - 2)
if n == 1 and m == 1:
return 1
if n == 2 or m == 2:
return 0
if n == 1 and m > 2:
return m - 2
if n > 2 and m == 1:
return n - 2
return (n - 2) * (m - 2)
倒香槟:纯模拟
import sys
if __name__ == '__main__':
n, m = map(int, sys.stdin.readline().strip().split()))
max_v = list(map(int, sys.stdin.readline().strip().split()))
cur_v = [0] * n
order = list(map(int, sys.stdin.readline().strip().split()))
while order:
if order[0] == 1:
print(cur_v[order[1] - 1])
else:
put_in, put_v = order[1] - 1, order[2]
while put_v and put_in < n:
if (max_v[put_in] - cur_v[put_in]) > put_v:
cur_v[put_in] += put_v
put_v = 0
else:
put_v -= max_v[put_in] - cur_v[put_in]
cur_v[put_in] = max_v[put_in]
put_in += 1
order = list(map(int, sys.stdin.readline().strip().split()))
if __name__ == '__main__':
n, m = map(int, sys.stdin.readline().strip().split()))
max_v = list(map(int, sys.stdin.readline().strip().split()))
cur_v = [0] * n
order = list(map(int, sys.stdin.readline().strip().split()))
while order:
if order[0] == 1:
print(cur_v[order[1] - 1])
else:
put_in, put_v = order[1] - 1, order[2]
while put_v and put_in < n:
if (max_v[put_in] - cur_v[put_in]) > put_v:
cur_v[put_in] += put_v
put_v = 0
else:
put_v -= max_v[put_in] - cur_v[put_in]
cur_v[put_in] = max_v[put_in]
put_in += 1
order = list(map(int, sys.stdin.readline().strip().split()))