Cut the sticks

 1 def main():
 2     n = int(raw_input())
 3     arr = map(int, raw_input().strip().split())
 4
 5     for i in range(n):
 6         cutNum = 0
 7         minValue = min(arr)
 8         for _ in range(n):
 9             if 0 < arr[_] < 1001:
10                 arr[_] -= minValue
11                 cutNum += 1
12             if arr[_] <= 0: # 使不合适的值,脱衣循环
13                 arr[_] = 1001
14         if cutNum != 0: # 两层循环有富裕出来,所以只输出不为0的,编码的一种动态调整
15             print cutNum
16
17 main()

学习

  尝试

    pop等操作

//新的思路

 1 n = int(raw_input().strip())
 2 sticks = [int(i) for i in raw_input().strip().split()]
 3 sticks.sort()
 4 newItem = sticks[0]
 5 count = len(sticks)
 6 print count
 7 count -= 1
 8 for i in range(1, len(sticks)):
 9     if sticks[i] != newItem:
10         newItem = sticks[i]
11         print count
12     count -= 1

学习

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

时间: 2024-11-10 19:25:19

Cut the sticks的相关文章

hdu1455 Sticks 深搜 强剪枝

Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6035    Accepted Submission(s): 1704 Problem Description George took sticks of the same length and cut them randomly until all parts becam

PKU1011 Sticks

Description George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the original state, but he forgot how many sticks he had originally and how long they were original

poj1011 Sticks

Description George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the original state, but he forgot how many sticks he had originally and how long they were original

POJ 1011 sticks 搜索

Sticks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 125918   Accepted: 29372 Description George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the or

POJ1011 Sticks 【剪枝】

Sticks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 122771   Accepted: 28441 Description George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the or

UVA 10003 - Cutting Sticks

#include<iostream> #include<map> #include<string> #include<cstring> #include<cstdio> #include<cstdlib> #include<cmath> #include<queue> #include<vector> #include<algorithm> using namespace std; in

UVA 10003 Cutting Sticks(区间dp)

Description  Cutting Sticks  You have to cut a wood stick into pieces. The most affordable company, The Analog Cutting Machinery, Inc. (ACM), charges money according to the length of the stick being cut. Their procedure of work requires that they onl

NYOJ 293 Sticks 【深搜】+【剪枝】

这是一道让人泪奔的题,它深刻的说明了什么是剪枝,哪怕是再小的一个细节,一旦递归规模增大都会引发巨大的时间消耗,真是神题~ Sticks 时间限制:3000 ms  |  内存限制:65535 KB 难度:5 描述 George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the

HDU5203 Rikka with wood sticks

Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: Yuta have a wood stick of length n which consists of n linked sticks of length 1. So it