Wooden Sticks

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

题解:

这道题目是先要排序的,按照长度或者重量排都可以,当长度(重量)相同时就按照重量(长度)排,从大到小或从小到大都可以!这里我懂的,没有问题!
排序之后,问题就可以简化,(假设按照长度不等时长度排,长度等是按照重量排,我假设按照从大到小来排!)即求排序后的所有的重量值最少能表示成几个集合。长度就不用再管了,从数组第一个数开始遍历,只要重量值满足条件,那么这两个木棍就满足条件!
 

 #include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
struct wooden{
int l,w;
};
wooden my[];
bool comp(wooden a,wooden b){
if(a.l>b.l)return ;
else if(a.l==b.l)
return a.w>b.w;
else return ;
}
int main()
{
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
int i=,j;
while(i<n)
{
scanf("%d %d",&my[++i].l,&my[i].w);
}
sort(my,my+n,comp);
int out=n;
for(i=;i<n;i++)
for(j=;j<=i-;j++){
if(my[j].l>=my[i].l&&my[j].w>=my[i].w){
out--;
my[j].l=my[i].l;
my[j].w=my[i].w;
my[i].l=;
my[i].w=;
break;
}
}
printf("%d\n",out);
}
return ;
}

Wooden Sticks -HZNU寒假集训的更多相关文章

  1. GlitchBot -HZNU寒假集训

    One of our delivery robots is malfunctioning! The job of the robot is simple; it should follow a lis ...

  2. 今年暑假不AC - HZNU寒假集训

    今年暑假不AC "今年暑假不AC?" "是的." "那你干什么呢?" "看世界杯呀,笨蛋!" "@#$%^&a ...

  3. FatMouse' Trade -HZNU寒假集训

    FatMouse' Trade FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the wa ...

  4. 畅通工程-HZNU寒假集训

    畅通工程 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只 ...

  5. 并查集模板题(The Suspects )HZNU寒假集训

    The Suspects Time Limit: 1000MS Memory Limit: 20000KTotal Submissions: 36817 Accepted: 17860 Descrip ...

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

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

  7. POJ 1065 Wooden Sticks

    Wooden Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16262 Accepted: 6748 Descri ...

  8. HDU ACM 1051/ POJ 1065 Wooden Sticks

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

  9. 1051 Wooden Sticks

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

随机推荐

  1. Struts2进阶(一)运行原理及搭建步骤

    Struts2进阶(一)运行原理 Struts2框架 Struts2框架搭建步骤 致力于web服务,不可避免的涉及到编程实现部分功能.考虑使用到SSH框架中的Struts2.本篇文章只为深入理解Str ...

  2. JSP连接MySQL时老是遇到驱动错误怎么办?

    在使用JSP进行web开发的时候总是会不可避免的遇到各种各样的问题.今天我也来讲一讲我遇到的一些奇葩的问题. 驱动出错 一开始我总是以为是我导入到工程的里的jar包的问题,于是我就试验了好几个连接My ...

  3. [C++学习历程]Visual Studio 2010 的HelloWorld

    大学时期曾学过C++的知识,那时候也没有使用VS这样高档的IDE工具,就是C++6.0那样来的.对于重新拾起C++来说,换了个IDE,那么就先从使用IDE学起吧~ 作者:苏生米沿 本文链接:http: ...

  4. Hadoop分布式存储系统HDFS

    1.hadoop fs 指令 -ls -ls <路径> 查看指定路径的当前目录结构 -lsr -lsr <路径> 递归查看指定路径的目录结构 -du -du <路径> ...

  5. catalina.sh设置JAVA_HOME后还无法解决更换JDK有关问题

    catalina.sh设置JAVA_HOME后还无法解决更换JDK问题 表示linux已经安装默认的JDK,需要查找配置文件,更换JDK路径为指定的路径 在root用户下 使用echo $PATH 查 ...

  6. javascript 把时间戳转为时间 ajax HTML拼装

    这个目的是记下来,好让我以后可以看一下,这个脚本可是反反复复写了我N天啊!! 全部写下,以备后用! Date.prototype.format = function(format) { var o = ...

  7. Synchronize 和 Lock 的区别与用法

    一.synchronized和lock的用法区别 (1)synchronized(隐式锁):在需要同步的对象中加入此控制,synchronized可以加在方法上,也可以加在特定代码块中,括号中表示需要 ...

  8. tar 压缩和解压缩使用笔记

    tar 压缩和解压缩使用笔记 1 文件 1.1 打包 1.1 压缩 $ tar czf myfile.txt.tar.gz ./myfile.txt 1.2 解压缩 解压缩到目录: $ mkdir o ...

  9. epoll通俗讲解

        转载地址:http://yaocoder.blog.51cto.com/2668309/888374     首先我们来定义流的概念,一个流可以是文件,socket,pipe等等可以进行I/O ...

  10. java线程池ThreadPoolExecutor 如何与 AsyncTask() 组合使用

    简单说下Executors类,提供的一系列创建线程池的方法: 他们都有两个构造方法 1. --------newFixedThreadPool (创建一个定长线程池,可控制线程最大并发数,超出的线程会 ...