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. chromium对网页获取favicon

    每一个网页都有一个favicon,在历史记录的保存中须要用到.在content文件夹下,这个没有实现. 以下说一下我的实现过程: web_contents_impl.cc文件里有方法:WebConte ...

  2. RecyclerView 缓存机制详解

    一 前言 RecyclerView据官方的介绍,该控件用于在有限的窗口中展示大量数据集,其实这样功能的控件我们并不陌生,例如:ListView.GridView.RecyclerView可以用来代替传 ...

  3. Spring9 : Autowire(自动装配)机制

    原文出处: 五月的仓颉 为什么Spring要支持Autowire(自动装配) 先写几个类,首先定义一个Animal接口表示动物: 1 2 3 4 5 public interface Animal { ...

  4. Kmeans聚类算法分析(转帖)

    原帖地址:http://www.opencvchina.com/thread-749-1-1.html       k-means是一种聚类算法,这种算法是依赖于点的邻域来决定哪些点应该分在一个组中. ...

  5. XSS第四节,XSS攻击实例(一)

    在开始实例的讲解之前,先看一下XSS的危害情况,第一张图中说明和XSS相关的CVE漏洞有7417个(http://web.nvd.nist.gov/view/vuln/search-results?q ...

  6. 关于编码问题,报错:'gbk' codec can't encode character '\u3164' in position 0: illegal multibyte sequence

    之前经常在写入文件的时候遇到这种报错, 'gbk' codec can't encode character '\u3164' in position 0: illegal multibyte seq ...

  7. 任务栈 启动模式 Task Flag launchMode MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  8. JavaScript快速检测浏览器对CSS3特性的支持情况

    项目中使用动画效果在IE9下不支持,所以写了个判断浏览器是否支持动画的函数,进而扩展到下面判断浏览器支持任一特定CSS3属性的函数. function supportAnimation(){ var ...

  9. 【nodejs】修改了下对股票表进行crud操作的代码

    表是这样的: id是自增长字段,code和name都是255位的varchar. 下面是主角app.js的代码: 'use strict'; var express=require('express' ...

  10. Silverlight 之 断点调试

    silverlight程序经常会遇到无法调试的情况,下面来总结解决方案. 一.问题描述 在Silverlight开发过程中,经常时不时的会碰到Silverlight无法调试的问题.如下几种情况: 1. ...