20190921網易,度小滿

網易

1.

 暴力60%

2.

t = int(input().strip())
for _ in range(t):
	n, m = map(int, input().strip().split())
	a = list(map(int, input().strip().split()))
	flag = True
	for i in range(n):
		res = a[i] - i
		m += res
		if m < 0:
			flag = False
			break
	print('YES' if flag else 'NO')

3.

第二個樣例輸出:NO

過30%+超時

t = int(input().strip())
for _ in range(t):
	n, k = map(int, input().strip().split())
	a = list(map(int, input().strip().split()))
	reach = [-1] * n
	queue = [0]
	while queue:
		tmp = queue.pop(0)
		reach[tmp] = 1
		for i in range(tmp+1, tmp+k+1):
			if i < n:
				if a[i] <= a[tmp]:
					queue.append(i)
				else:
					reach[i] = 0
	flag = reach[-1] == 1
	super_candi = [i for i in range(n) if reach[i] == 0]
	for candi in super_candi:
		new_reach = reach[:]
		new_queue = [candi]
		while new_queue:
			tmp = new_queue.pop(0)
			new_reach[tmp] = 1
			for i in range(tmp+1, tmp+k+1):
				if i < n and a[i] <= a[tmp]:
					new_queue.append(i)
		flag = flag or new_reach[-1] == 1
	print('YES' if flag else 'NO')

4.

分析:

直接兩層循環過60%,超時

度小滿

1.

 

2.

 9%

3.

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章