Wooden Sticks

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 22000    Accepted Submission(s): 8851

Problem 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 (4,9), (5,2), (2,1), (3,5), and (1,4), then the minimum setup time should be 2 minutes since there is a sequence of pairs (1,4), (3,5), (4,9), (2,1), (5,2).
 
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 n 2 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
 
Source
思路:将木棒按l,w 递减的顺序排列,统计关于递减的连续子列的个数即为答案。
代码:

 #include "cstdio"
 #include "iostream"
 #include "algorithm"
 #include "string"
 #include "cstring"
 #include "queue"
 #include "cmath"
 #include "vector"
 #include "map"
 #include "stdlib.h"
 #include "set"
 #define mj
 #define db double
 #define ll long long
 using  namespace std;
 ;
 ;
 ;
 bool u[N];
 typedef  struct stu{
     int l,w;
 }M;
 M s[];
 int cmp(M a,M b)
 {
     if(a.l==b.l) return a.w>=b.w;
     return a.l>=b.l;
 }
 int main()
 {
     int t,n,i,j,ans;
     scanf("%d",&t);
     while(t--)
     {
         scanf("%d",&n);
         ;i<n;i++)
             scanf(;
         sort(s,s+n,cmp);
         int mi;
         ans=;
         ;i<n;i++)
         {
             if(u[i]) continue;
             mi=s[i].w;
             ;j<n;j++)
             {
                 if(!u[j]&&s[j].w<=mi){
                     mi=s[j].w;
                     u[j]=;
                 }
             }
             ans++;
         }
         printf("%d\n",ans);
     }
     ;
 }
 

HDU 1051 Wooden Sticks 贪心||DP的更多相关文章

  1. HDU 1051 Wooden Sticks (贪心)

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  2. HDU - 1051 Wooden Sticks 贪心 动态规划

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)    ...

  3. HDU 1051 Wooden Sticks 贪心题解

    本题一看就知道是最长不减序列了,一想就以为是使用dp攻克了. 只是那是个错误的思路. 我就动了半天没动出来.然后看了看别人是能够使用dp的,只是那个比較难证明其正确性,而其速度也不快.故此并非非常好的 ...

  4. hdu 1051 wooden sticks (贪心+巧妙转化)

    #include <iostream>#include<stdio.h>#include<cmath>#include<algorithm>using ...

  5. hdu 1051:Wooden Sticks(水题,贪心)

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  6. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  7. HDOJ.1051 Wooden Sticks (贪心)

    Wooden Sticks 点我挑战题目 题意分析 给出T组数据,每组数据有n对数,分别代表每个木棍的长度l和重量w.第一个木棍加工需要1min的准备准备时间,对于刚刚经加工过的木棍,如果接下来的木棍 ...

  8. HDU 1051 Wooden Sticks 造木棍【贪心】

    题目链接>>> 转载于:https://www.cnblogs.com/Action-/archive/2012/07/03/2574800.html  题目大意: 给n根木棍的长度 ...

  9. HDU 1051 Wooden Sticks

    题意: 有 n 根木棒,长度和质量都已经知道,需要一个机器一根一根地处理这些木棒. 该机器在加工过程中需要一定的准备时间,是用于清洗机器,调整工具和模板的. 机器需要的准备时间如下: 1.第一根需要1 ...

随机推荐

  1. 初码-Azure系列-文章目录

    系统迁移 初码-Azure系列-记一次MySQL数据库向Azure的迁移 初码-Azure系列-迁移PHP应用至Azure的一些实践记录和思考 初码-Azure系列-记一次从阿里云到Azure的迁移和 ...

  2. Js获取url传递过来的参数

    原理跟取cookie值一样的 function getParamer(paramer){ var url=window.location.href.split("?")[1];/* ...

  3. 刨根究底字符编码之十一——UTF-8编码方式与字节序标记

    UTF-8编码方式与字节序标记 一.UTF-8编码方式 1. 接下来将分别介绍Unicode字符集的三种编码方式:UTF-8.UTF-16.UTF-32.这里先介绍应用最为广泛的UTF-8. 为满足基 ...

  4. vuex所有核心概念完整解析State Getters Mutations Actions

    vuex是解决vue组件和组件件相互通信而存在的,vue理解起来稍微复杂但一旦看懂择即为好用 安装: npm install --save vuex 引入 import Vuex from 'vuex ...

  5. Nodejs-express 4.0框架 简单介绍

    http://www.expressjs.com.cn/4x/api.html  这个是express API的中文手册 但是只是翻译了一点 英语比较差比较难受. 1. 关于安装 现在网上查的时候有一 ...

  6. ReactJS入门基础

    渲染这俩字可能在很多地方都见过.但可能不太理解是啥意思. 那么首先我们来理解一下渲染. 渲染 我觉得这样理解比较通俗. 我们做一个汽车,开始是没有喷漆的(没有css) 只是些框框架架(HTML标签). ...

  7. angular.js的ng-app 指令定义一个 AngularJS 应用程序。

    <!DOCTYPE html> <html lang="en" ng-app> <head> <meta charset="UT ...

  8. 尝试向树莓派3B引入Drbian 9 arm64-PART 1

    Stage 1:试图加入arm64软件包 笔者默认您清楚这些指令背后的意义以及其可能造成的后果,并默认您已备份重要资料 sudo dpkg --add-archietcture arm64 sudo ...

  9. spring boot 入门操作(三)

    spring boot入门操作 devtools热部署 pom dependencies里添加依赖 <dependency> <groupId>org.springframew ...

  10. [1] MVC & MVP &MVVM

    开发架构之MVC & MVP & MVVM