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. 普通01背包问题(dp)

    有n个物品,重量和价值分别为wi和vi,从这些物品中挑选出重量不超过W的物品,求所有挑选方案中物品价值总和的最大值 限制条件: 1 <= n <= 100; 1 <= wi,vi & ...

  2. laravel控制器方法中,用函数作为变量进行传递时的处理方法

    本人在做上传图片时,里面执行的方法时一致的,只是个别地方不同,这种情况下,就需要把公用的部分提取出来,把不同的地方放到回调函数种去. StudentController中的方法: public fun ...

  3. (路-莫)-Python基础一

    一,Python介绍 1,python的出生与应用 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆(中文名字:龟叔)为了在阿姆斯特丹打 ...

  4. bzoj3879

    题解: 后缀数组 然后把读入的内容去重,按照rank排序 然后用单调栈处理一下 代码: #include<bits/stdc++.h> using namespace std; typed ...

  5. compile openjdk7 in ubuntu OS

    success: openjdk version "1.7.0-internal"OpenJDK Runtime Environment (build 1.7.0-internal ...

  6. debian系统下安装ssh

    SSH 为 Secure Shell 的缩写,SSH 为建立在应用层基础上的安全协议.SSH 是目前较可靠,专为远程登录会话和其他网络服务提供安全性的协议.利用 SSH 协议可以有效防止远程管理过程中 ...

  7. Linux系统下yum源配置(Centos 6)

    1.备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 2.下载新的CentOS-Base ...

  8. 7系列FPGA远程更新方案-QuickBoot(转)

    reference: http://xilinx.eetrend.com/d6-xilinx/article/2014-04/7009.html reference :  quickboot meth ...

  9. java Dom4j xml 写

    手动拼接xml 并返回 依赖包 <dependency> <groupId>dom4j</groupId> <artifactId>dom4j</ ...

  10. a recipe kindly provided by Dimas for kikuchi

    https://sianipar17.com/2017/12/14/tutorial-for-teleseismic-body-wave-inversion-program/