http://acm.hdu.edu.cn/showproblem.php?pid=1051

Wooden Sticks

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

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

题目大意:

有一堆n个木棍,长度质量已知,机器处理木棍需要设置时间,规定

(1)第一根木棍的设置时间是1min

(2)前一个处理的木棍长度和质量小于等于后一个就不用设置时间,否则需要1min设置

找到最小建立时间。

如 给出(4,9)(5,2)(2,1)(3,5)(1,4)则最小建立时间(1,4)(3,5)(4,9)(2,1)(5,2)。

(本来想找个贪心的水题耍一下..结果发现完全看不出这道题的贪心解法...然后想到之前做的一个导弹拦截的问题..感觉二者有异曲同工之妙..

题目分析:首先按照长度进行排序..长度相同的按照重量排序..然后就能直接取了??(假的贪心..很容易找到hack数据..我的做法是在排序之后..从后往前找到这段数字的最长上升子序列的长度K,..则.K就是答案..这一点和导弹拦截的那题几乎一致。

导弹拦截http://acm.hdu.edu.cn/showproblem.php?pid=1257

 #include <bits/stdc++.h>

 using namespace std;

 struct pot{
int len;
int weig;
}qwq[];
bool cmp(struct pot aa,struct pot bb){
if(aa.len!=bb.len)
return aa.len < bb.len;
return aa.weig < bb.weig;
}
int main()
{
int nums[];
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
memset(nums,,sizeof(nums));
for(int i = ; i < n; i++){
scanf("%d%d",&qwq[i].len,&qwq[i].weig);
}
sort(qwq,qwq+n,cmp);
int dp[];
int tot=;
dp[]=qwq[n-].weig;
int maxx=qwq[n-].weig;
for(int i = n- ; i >= ; i--){
if(qwq[i].weig>dp[tot]){
dp[++tot]=qwq[i].weig;
maxx=dp[tot];
}
else{
int l=;
int r=tot;
while(l<=r){
int mid=(l+r)/;
if(dp[mid]>=qwq[i].weig){
r=mid-;
}
else {
l=mid+;
} }
dp[l]=qwq[i].weig;
}
}
cout << tot <<endl;
}
return ;
}

(貌似导弹拦截那题大多数人也是使用贪心..(> _ <)

【HDOJ1051】【排序+LIS】【贪心】的更多相关文章

  1. BZOJ_1697_[Usaco2007 Feb]Cow Sorting牛排序_贪心

    BZOJ_1697_[Usaco2007 Feb]Cow Sorting牛排序_贪心 Description 农夫JOHN准备把他的 N(1 <= N <= 10,000)头牛排队以便于行 ...

  2. cf 之lis+贪心+思维+并查集

    https://codeforces.com/contest/1257/problem/E 题意:有三个集合集合里面的数字可以随意变换位置,不同集合的数字,如从第一个A集合取一个数字到B集合那操作数+ ...

  3. Uva11292--------------(The Dragon of Loowater)勇者斗恶龙 (排序后贪心)

    ---恢复内容开始--- 题目: Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major ...

  4. Vijos p1303导弹拦截(LIS+贪心)

    传送门:https://vijos.org/p/1303 背景 实中编程者联盟为了培养技术精湛的后备人才,必须从基础题開始训练. 描写叙述 某国为了防御敌国的导弹突击,研发出一种导弹拦截系统. 可是这 ...

  5. Problem #3263 丽娃河的狼人传说 区间满足灯数,r排序后贪心。

    丽娃河的狼人传说 Time limit per test: 1.0 seconds Time limit all tests: 1.0 seconds Memory limit: megabytes ...

  6. BZOJ 1697: [Usaco2007 Feb]Cow Sorting牛排序(置换+贪心)

    题面 Description 农夫JOHN准备把他的 N(1 <= N <= 10,000)头牛排队以便于行动.因为脾气大的牛有可能会捣乱,JOHN想把牛按脾气的大小排序.每一头牛的脾气都 ...

  7. BZOJ 1046 [HAOI2007]上升序列(LIS + 贪心)

    题意: m次询问,问下标最小字典序的长度为x的LIS是什么 n<=10000, m<=1000 思路: 先nlogn求出f[i]为以a[i]开头的LIS长度 然后贪心即可,复杂度nm 我们 ...

  8. CF思维联系--CodeForces -214C (拓扑排序+思维+贪心)

    ACM思维题训练集合 Furik and Rubik love playing computer games. Furik has recently found a new game that gre ...

  9. Codeforces Round #404 (Div. 2)(A.水,暴力,B,排序,贪心)

    A. Anton and Polyhedrons time limit per test:2 seconds memory limit per test:256 megabytes input:sta ...

随机推荐

  1. 【框架】Testng用例失败自动重跑(五)

    arrow是testng的一个扩展插件,参考arrow的源代码 1.新建一个工程,结果如图: 2.RetryListener.java的代码 package com.netease.qa.testng ...

  2. LY.JAVA面向对象编程.形式参数和返回值

    2018-07-09 13:29:16 运动员和教练案例 /* 教练和运动员案例(学生分析然后讲解) 乒乓球运动员和篮球运动员. 乒乓球教练和篮球教练. 为了出国交流,跟乒乓球相关的人员都需要学习英语 ...

  3. 解决eclipse/myeclipse导入项目时出现红色叹号的方法

  4. laravel Eloquent 查询数据库判断获取的内容是否为空

    原文地址:https://www.cnblogs.com/love-snow/articles/7205338.html 在使用 Laravel Eloquent 模型时,我们要判断取出的结果集是否为 ...

  5. hibernate创建构架

    创建hibernate架构: 注意:需要将所需的架包导进去: 二:Java工程的具体结构: 具体代码如下:hibernate.cfg.xml <!DOCTYPE hibernate-config ...

  6. zookeeper集群环境搭建(使用kafka的zookeeper搭建zk集群)

    ---恢复内容开始--- 使用kafka的zookeeper来搞集群的话和单纯用zk的其实差不了多少. 0.说在前头,搭建kafka集群之前请把每个服务器的jdk搞起来. 1.安装kafka wget ...

  7. TTL反相器的外部特性

    TTL反相器的外部特性 电压传输特性 输入端噪声容限特性 静态输入特性: 静态输出特性: 动态特性: 传输延迟时间:是由晶体管的延迟时间,电阻以及寄生电容元素引起的.包括俩部分:输入由低电平跳为高电平 ...

  8. JDBC:随机生成车牌号,批量插入数据库

    package InsertTest; /* * 单客户端:批量插入 */ import java.sql.Connection; import java.sql.DriverManager; imp ...

  9. 搭建Hadoop2.7.1的分布式集群

    Hadoop 2.7.1 (2015-7-6更新),hadoop的环境配置不是特别的复杂,但是确实有很多细节需要注意,不然会造成许多配置错误的情况.尽量保证一次配置正确防止反复修改. 网上教程有很多关 ...

  10. [leetcode整理]

    =======简单 leetcode164 Maximum Gap sort两次 =======有参考 330 Patching Array 98 Validate Binary Search Tre ...