Cut the sticks

时间:2022-03-30 10:52:22
 def main():
n = int(raw_input())
arr = map(int, raw_input().strip().split()) for i in range(n):
cutNum = 0
minValue = min(arr)
for _ in range(n):
if 0 < arr[_] < 1001:
arr[_] -= minValue
cutNum += 1
if arr[_] <= 0: # 使不合适的值,脱衣循环
arr[_] = 1001
if cutNum != 0: # 两层循环有富裕出来,所以只输出不为0的,编码的一种动态调整
print cutNum main()

学习

  尝试

    pop等操作

//新的思路

 n = int(raw_input().strip())
sticks = [int(i) for i in raw_input().strip().split()]
sticks.sort()
newItem = sticks[0]
count = len(sticks)
print count
count -= 1
for i in range(1, len(sticks)):
if sticks[i] != newItem:
newItem = sticks[i]
print count
count -= 1

学习

  对于顺序不重要的,完全是可以进行先排序再来的