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. global 全局变量 nonlocal 局部变量

    # x= # def func(): # x= # # func() # print(x) # x=[] # def func(): # x.append() # x.append() # x.app ...

  2. pyhton字符串

    a = 5 # 1 + 1 = 10 + 1 = 11 + 1 = 100 + 1 = 101print(a.bit_length()) # 计算一个数字的二进制长度. a = 10# print(t ...

  3. linux下 gogs的安装和web钩子

    linux系统下 gogs下载安装以及web钩子的使用 (1)下载gogs  官方网址:https://dl.gogs.io/ 选择合适的版本,解压后就可以使用了 启动gogs的命令:  ./gos ...

  4. sqlalchemy tree 树形分类 无限极分类的管理。预排序树,左右值树。sqlalchemy-mptt

    简介: 无限极分类是一种比较常见的数据格式,生成组织结构,生成商品分类信息,权限管理当中的细节权限设置,都离不开无限极分类的管理. 常见的有链表式,即有一个Pid指向上级的ID,以此来设置结构.写的时 ...

  5. 首次编译Java小程序

    public class helloworld { public static void main(string[] args) { system.out.println("hello wo ...

  6. C++关于运算符的注意事项

    1.函数调用也是一种特殊的运算符,对运算对象的个数不作限制. 2.几元运算符,是基于作用的对象的数量. 3.不同类型的运算对象进行运算,可能会出现类型转换,一般情况下小整数类型会被转换成较大的整数类型 ...

  7. Android知识补充(Android学习笔记)

    Android知识补充 ●国际化 所谓的国际化,就是指软件在开发时就应该具备支持多种语言和地区的功能,也就是说开发的软件能同时应对不同国家和地区的用户访问,并针对不同国家和地区的用户,提供相应的.符合 ...

  8. vuesheng生命周期

    对着官网的demo写例子,碰到了生命周期钩子方法,之前只是根据官网的图,了解了大概, 现在忍不住想去深扒一下,因此找了几个博客看了下,受益匪浅,故此笔记: 参考:http://www.cnblogs. ...

  9. 九、编写led驱动

    led.c #include <linux/init.h> #include <linux/module.h> #include <linux/cdev.h> #i ...

  10. PODOFO编译

    由于LibHaru库只能创建PDF,所以只能换了. PODOFO项目的依赖项目有: FreeType2: https://sourceforge.net/projects/freetype/files ...