Codeforces Round #420 (Div. 2) A B C

来源:互联网 发布:按键精灵安卓网络验证 编辑:程序博客网 时间:2024/06/07 00:23

A. Okabe and Future Gadget Laboratory

# Time   : 2017-6-26 10:30# Auther : Anjone# URL : http://codeforces.com/contest/821/problem/An = int(input())arr = [ list(map(int,input().split())) for i in range(n)]for i in range(n):for j in range(n):if( arr[i][j] != 1):cnt = 0for k in range(n):for l in range(n):if(arr[i][k] + arr[l][j] == arr[i][j]):cnt += 1if(cnt == 0):print("No")exit(0)print ("Yes")

B. Okabe and Banana Trees

# Time   : 2017-6-26 13:30# Auther : Anjone# URL : http://codeforces.com/contest/821/problem/B# 对于一个确定的y找到最大的x#         x    y# getsum  ∑ (  ∑ (i+j) ) = (y+1)*(x+y)*(x+1)/2#        i=0  j=0getsum = lambda x,y : ( y + 1 ) * ( x + y ) * (x+1) // 2m,b = map(int,input().split())ans = 0for i in range(b+1):x = (b-i)*mans = max(ans, getsum(x,i))print(ans)

C. Okabe and Boxes

# Time   : 2017-6-26 14:30# Auther : Anjone# URL : http://codeforces.com/contest/821/problem/C# 题意 :模拟进栈出栈 要求出栈顺序需要递增# 思路 :保证当前栈顶元素为num,若不是更新栈排序#栈排序后 下次出栈时判断为空 出栈元素必有序ans = 0num = 1stack = []n = int(input())for i in range(2*n):s = input()if s.find("add") != -1:stack.append(int(s.split()[1]) )else:if len(stack) != 0 and stack[-1] != num:stack = []ans+=1if len(stack):stack.pop()num += 1print(ans)