Wooden Sticks

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

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
采用的是,常规的方法。。。。
先进行排序,人选一个作为第一优先级...
比如以第一个聚类...以重量作为依据排序..
2 1
5 2
1 4
3 5
4 9
序列排好了...然后那样每次拿掉一条递增的序列,并统计即可!
代码:

 #include<cstdio>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
typedef struct
{
int we;
int le;
int tag;
}go;
int cmp(go const a, go const b)
{
/*升序*/
if(a.le==b.le)
{
if(a.we<b.we) return ;
else return ;
}
if(a.le<b.le) return ;
else return ;
}
int main()
{
int t,n,cnt;
vector<go>st;
go tem;
scanf("%d",&t);
while(t--)
{
st.clear();
scanf("%d",&n);
while(n--)
{
scanf("%d%d",&tem.le,&tem.we);
tem.tag=true;
st.push_back(tem);
}
sort(st.begin(),st.end(),cmp);
vector<go>::iterator it,tem;
cnt=;
bool falg;
while(!st.empty())
{
falg=true;
for(it=st.begin(); it!=st.end();it++)
{
if(it->tag&&falg) tem=it;
if(it->tag&&tem->we<=it->we)
{
tem=it;
it->tag=false;
falg=false;
}
}
if(!falg) cnt++;
else break;
}
printf("%d\n",cnt);
}
return ;
}

HDUOJ------------1051Wooden Sticks的更多相关文章

  1. hdu 1051Wooden Sticks

    #include<cstdio> #include<cstring> #include<algorithm> #define maxn 10000 using na ...

  2. hduoj 1455 && uva 243 E - Sticks

    http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...

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

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

  4. POJ 2653 Pick-up sticks (线段相交)

    题意:给你n条线段依次放到二维平面上,问最后有哪些没与前面的线段相交,即它是顶上的线段 题解:数据弱,正向纯模拟可过 但是有一个陷阱:如果我们从后面向前枚举,找与前面哪些相交,再删除前面那些相交的线段 ...

  5. POJ 2653 Pick-up sticks【线段相交】

    题意:n根木棍随意摆放在一个平面上,问放在最上面的木棍是哪些. 思路:线段相交,因为题目说最多有1000根在最上面.所以从后往前处理,直到木棍没了或者最上面的木棍的总数大于1000. #include ...

  6. POJ1065Wooden Sticks[DP LIS]

    Wooden Sticks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21902   Accepted: 9353 De ...

  7. 【POJ 2653】Pick-up sticks 判断线段相交

    一定要注意位运算的优先级!!!我被这个卡了好久 判断线段相交模板题. 叉积,点积,规范相交,非规范相交的简单模板 用了“链表”优化之后还是$O(n^2)$的暴力,可是为什么能过$10^5$的数据? # ...

  8. CF451A Game With Sticks 水题

    Codeforces Round #258 (Div. 2) Game With Sticks A. Game With Sticks time limit per test 1 second mem ...

  9. POJ 2452 Sticks Problem

    RMQ+二分....枚举 i  ,找比 i 小的第一个元素,再找之间的第一个最大元素.....                   Sticks Problem Time Limit: 6000MS ...

  10. The 2015 China Collegiate Programming Contest D.Pick The Sticks hdu 5543

    Pick The Sticks Time Limit: 15000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others ...

随机推荐

  1. C#常使用的正则表达式

    /// <summary> /// 是否为手机号码 /// </summary> /// <param name="value"></pa ...

  2. OpenCV学习(18) 细化算法(6)

    本章我们在学习一下基于索引表的细化算法. 假设要处理的图像为二值图,前景值为1,背景值为0. 索引表细化算法使用下面的8邻域表示法: 一个像素的8邻域,我们可以用8位二进制表示,比如下面的8邻域,表示 ...

  3. libjson 编译和使用 - 2. 配置使用lib文件

    以下转自:http://blog.csdn.net/laogong5i0/article/details/8223448 1. 在之前的libjson所在的解决方案里新建一个控制台应用程序,叫Test ...

  4. 曲线平滑-B样条曲线 【转】

    版权声明:本文为博主原创文章,未经博主允许不得转载. 3D空间曲线三次B样条平滑示例: struct D_DOT3D //D_DOT3D示例,未完全实现 { double x,y,z; } doubl ...

  5. C#创建一个Windows Service

    Windows Service这一块并不复杂,但是注意事项太多了,网上资料也很凌乱,偶尔自己写也会丢三落四的.所以本文也就产生了,本文不会写复杂的东西,完全以基础应用的需求来写,所以不会对Window ...

  6. Android硬件入门-照相机

    学习Android不能不学习照相机,现在各种美容相机,微信朋友圈发图,现在升级之后直接下拉就可以照相了,各种艳照的的源头也是照相机,扯远了,有点邪恶了,还是简单学习一下Android中照相机的使用,A ...

  7. Sqlserver2008相关配置问题

    一:ReportServices  无法连接Report Services 数据库服务 SSRS连接不了ReportServer (安装数据库的时候默认安装的一个报表服务数据库) 原因:装系统之后改了 ...

  8. FrameWork逆向工程之MotioPI

    在BI项目建设的过程中我们一般都是有备份的,而且这个是必须有的!特别是例如ETL Model,还有Data Model这一类的元数据,这些东西如果我们没有备份,而恰好的我们的开发模型又在某一天离我们而 ...

  9. [转载]C++中处理XML文件

      写Unmanaged Code在.NET时代成为一种很悲惨的事,当你需要处理XML文件时,这种感觉会变得尤其强烈.FCL中的System.XML多简单啊,连Steve Ballmer都知道怎么用. ...

  10. S5PV210开发系列三_简易Bootloader的实现

    S5PV210开发系列三 简易Bootloader的实现 象棋小子          1048272975 Bootloader是嵌入式系统上电后第一段运行的代码.对于功能简单的处理器,可能并没有Bo ...