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. 用大白菜U盘安装:[3]Ghost版Win7系统

    Ghost版Win7系统安装步骤: 1,先下载Ghost Win7系统到硬盘中,然后在U盘或其它硬盘根目录中新建一个GHO文件夹,注意:决不能把文件夹建在C盘(系统盘)中,然后用UltraISO或者W ...

  2. Java使用wait() notify()方法操作共享资源

    Java多个线程共享资源: 1)wait().notify()和notifyAll()方法是本地方法,并且为final方法,无法被重写. 2)调用某个对象的wait()方法能让当前线程阻塞,并且当前线 ...

  3. 数据泵导入 ORA-31626

    Oracle,10G,数据泵导入时,报错如下: 解决方案:对当前用户做如下授权 . 具体操作:grant connect,resource to user;

  4. nginx;keepalived配置出现主主的解决方法(脑裂问题)

    1.查看日志 tail -f /var/log/messages 发现master和backup机都是mastaer模式启动的 通过查看别人的经历,发现VRRP基于报文实现的.master设置一定时间 ...

  5. 【原创】<Debug> QString

    [问题1] 'class QString' has no member named 'toAscii' [解答] 把toAscii().data()改成toLatin1().data() 如果QStr ...

  6. JavaScript 操作DOM对象

    1)JavaScript  操作DOM對象 1.DOM:是Document  Object  Model 的缩写,及文档对象模型 2.DOM通常分为三类:DOM Core(核心).HTML-DOM 和 ...

  7. java套接字(socket)实例

    客户端socket 流程: 1.连接远程主机 2.发送数据 3.接收数据 4.关闭流与socket连接 实例: import java.io.*; import java.net.Socket; im ...

  8. 【转】MySQL实现Oracle里的 rank()over(ORDER BY) 功能

    Oracle rank()和dense_rank()的区别是: –rank()是跳跃排序,有两个第二名时接下来就是第四名 –dense_rank()l是连续排序,有两个第二名时仍然跟着第三名 sele ...

  9. lxml简单用法 解析网页

    import requests s=requests.Session() re=s.get(lgurl,headers=headers)  #此处s可以直接换成requests the_page=re ...

  10. 玩转X-CTR100 l STM32F4 l DAC数字模拟转换

    我造轮子,你造车,创客一起造起来!塔克创新资讯[塔克社区 www.xtark.cn ][塔克博客 www.cnblogs.com/xtark/ ]      本文介绍X-CTR100控制器 DAC接口 ...