`
isiqi
  • 浏览: 16551213 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

PKUOJ1065 Wooden Sticks

J# 
阅读更多
Wooden Sticks
Time Limit:1000MS Memory Limit:10000K
Total Submissions:11794 Accepted:4808

Description

There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some time, called setup time, for the machine to prepare processing a stick. The setup times are associated with cleaning operations and changing tools and shapes in the machine. The setup times of the woodworking machine are given as follows:
(a) The setup time for the first wooden stick is 1 minute.
(b) Right after processing a stick of length l and weight w , the machine will need no setup time for a stick of length l' and weight w' if l <= l' and w <= w'. Otherwise, it will need 1 minute for setup.
You are to find the minimum setup time to process a given pile of n wooden sticks. For example, if you have five sticks whose pairs of length and weight are ( 9 , 4 ) , ( 2 , 5 ) , ( 1 , 2 ) , ( 5 , 3 ) , and ( 4 , 1 ) , then the minimum setup time should be 2 minutes since there is a sequence of pairs ( 4 , 1 ) , ( 5 , 3 ) , ( 9 , 4 ) , ( 1 , 2 ) , ( 2 , 5 ) .

Input

The input consists of T test cases. The number of test cases (T) is given in the first line of the input file. Each test case consists of two lines: The first line has an integer n , 1 <= n <= 5000 , that represents the number of wooden sticks in the test case, and the second line contains 2n positive integers l1 , w1 , l2 , w2 ,..., ln , wn , each of magnitude at most 10000 , where li and wi are the length and weight of the i th wooden stick, respectively. The 2n integers are delimited by one or more spaces.

Output

The output should contain the minimum setup time in minutes, one per line.

Sample Input

3 
5 
4 9 5 2 2 1 3 5 1 4 
3 
2 2 1 1 2 2 
3 
1 3 2 2 3 1 

Sample Output

2
1
3
【题意】

有n根木棍,每根木棍有不同的长度和重量。用一台机器来处理这些木棍,当第i+1根木棍的长度>=第i根木棍的长度 && 第i+1根木棍的重量>=第i根木棍的重量时,机器处理木棍的单位时间setup time加1,求出处理完n根木棍所需要的最少时间

【题解】

按木棍的长度从小到大排序,当木棍长度相等时,按重量小到大排序。然后依次选择比当前长度大的木棍(已经对木棍进行排序,每次选择都是对后面影响最小的),对选过的木棍进行标记。一轮之后,setup time+1,再对剩下的木棍进行选择,即可得到最优解。

分享到:
评论

相关推荐

    贪心算法 WOODEN STICKS 实例代码

    Problem DescriptionThere is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs...

    WoodenSticks

    Wooden Stickes 问题 现有n 根木棒,已知它们的长度和重量。要用一部木工机一根根加工,该机器在加工过程中需要一定的准备时间,是用于清洗机器在,调整工具和模板。 木工机需要的准备时间如下: (1)第1根需要1...

    桌面便签软件Sticks

    《Sticks:一款高效便捷的桌面便签软件》 在我们的日常工作中,高效的时间管理和任务组织至关重要。桌面便签作为一种简单实用的工具,已经成为许多人的首选。今天我们要介绍的是一款名为“Sticks”的桌面便签软件,...

    zju1025.rar_ZJU_acm zju 10_pid_sticks_zju 1025

    【标题】"ZJU1025 Wooden Sticks" 是浙江大学(Zhejiang University,简称ZJU)在线编程竞赛平台ACM上的一道题目,编号为1025。这道题目主要考察参赛者的算法设计和实现能力,属于计算机科学中的经典问题。 【描述...

    Wood Sticks

    "Wood Sticks"似乎是一个与自然元素相关的字体主题,从标题和描述中我们可以推测这可能是一款带有木质质感或者自然风格的字体。 "Wood Sticks"字体可能是设计师为了创造一种独特的视觉效果,模拟了木质材料的质感,...

    sticks_backtracking

    sticks cutting problem sticks are cut randomly until all parts became less than 50 units long. Now to return sticks to the original state. This program is designed to compute the smallest possible ...

    POJ1011-Sticks

    【标题】"POJ1011 - Sticks" 是一个经典的计算机编程竞赛题目,源自北京大学的在线评测系统POJ(PKU Online Judge)。这个题目挑战程序员解决与几何图形和数学逻辑相关的问题。 【描述】该题目的核心是求解在二维...

    tech_shape_sticks

    tech_shape_sticks

    poj 2452 Sticks Problem.md

    poj 2452 Sticks Problem.md

    kdev_t.rar_sticks

    【标题】"kdev_t.rar_sticks"是一个与操作系统内核设备驱动相关的代码示例,主要涉及`kdev_t`数据类型以及如何处理设备标识符。这个压缩包包含了一些源代码文件,它们可能是用于测试、演示或实现特定功能的。 ...

    ice_sticks

    "ice_sticks"这个标题可能是指一款独特的字体设计或者一个与冰棍(ice sticks)主题相关的创意字体项目。这个项目可能旨在创造一种新颖、有趣或引人入胜的视觉效果,让人联想到冰凉、清爽的感觉,正如冰棍在炎炎夏日...

    bailian.openjudge.cn 1011 sticks

    bailian.openjudge.cn 1011 sticks

    抽象精品ppt模板tech_shape_sticks056

    抽象精品ppt模板tech_shape_sticks056

    POJ2513-Colored Sticks【TrieTree+MergeSet+EulerPath】

    【标题】"POJ2513-Colored Sticks【TrieTree+MergeSet+EulerPath】"涉及的是一道编程竞赛题目,主要考察参赛者的数据结构与算法应用能力,特别是Trie树(字典树)、并查集(MergeSet)以及欧拉路径(Euler Path)这...

    POJ 1011_sticks.rar

    详细解释 ,既有源代码又有书面文字解释,ppt,在VC6上完成

    Pavilion Competition+Swiss-ster+Sticks.pdf

    近年来,以【Pavilion Competition+Swiss-ster+Sticks】为代表的竞赛项目,更是吸引了世界各国建筑学子的目光,成为了展现其设计才华的重要窗口。该竞赛邀请了来自全球各大建筑院校的优秀学生,围绕着为瑞士联邦理工...

Global site tag (gtag.js) - Google Analytics