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. 深度学习阅读列表 Deep Learning Reading List

    Reading List List of reading lists and survey papers: Books Deep Learning, Yoshua Bengio, Ian Goodfe ...

  2. Convert Sorted Array to Binary Search Tree leetcode java

    题目: Given an array where elements are sorted in ascending order, convert it to a height balanced BST ...

  3. 使用svgdeveloper 和 svg-edit 绘制svg地图

    目录: 1. 描述 2. 准备工作 3. 去除地图模板上的水印(可跳过) 4. 方法一.SVGDeveloper 5. 方法二.SVG-Edit 1. 描述编辑   有的时候我们需要自定义地图,本文提 ...

  4. [JSP]JSP中include指令和include动作的差别

    include指令是编译阶段的指令,即include所包括的文件的内容是编译的时候插入到JSP文件里,JSP引擎在推断JSP页面未被改动,否则视为已被改动. 因为被包括的文件是在编译时才插入的.因此假 ...

  5. 【BZOJ2662】【BeiJing wc2012】冻结 分层图 裸的!

    我都不好意思发题解了,看这篇博吧.(飞行路线的,基本一样) http://blog.csdn.net/vmurder/article/details/40075989 同学做了好久.我害怕题里有坑,又 ...

  6. ComboBoxEdit 数据绑定 使用模板

    1)定义模板资源 <UserControl.Resources> <local:StatusConvertor x:Key="StatusConvertor"&g ...

  7. xshell实现端口转发

    跳板机:10.127.10.1 目标机:10.127.4.25:8080 目的:出于安全,本地电脑是与远程服务器是网关不通的,为了能访问远程服务器数据必须做端口转发 SSH连接与身份认证为跳板机账号密 ...

  8. Cognos开发自定义排序规则的报表和自定义排名报表

    场景:有一个简单的销售数据分析,可以按照日期,按照商品类型来分析订单笔数和订单金额. 目的:用户可以自定义查看按照不同指标排序的数据,用户可以查看按照不同指标排名的前N名数据 一:功能及效果展示 效果 ...

  9. MATLAB数据处理快速学习教程

    转自:http://blog.csdn.net/abcjennifer/article/details/7706581 本篇内容集合了MATLAB中的基本操作.数据存储与计算.数据的直线与曲线拟合与画 ...

  10. PreferenceScreen的应用

    PreferenceScreen preference是偏好.首选的意思,PreferenceScreen个人翻译成 "偏好显示",明确这个意思就好.就是说依据特点灵活的定义显示内 ...