Wooden Sticks -HZNU寒假集训
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寒假集训的更多相关文章
- GlitchBot -HZNU寒假集训
One of our delivery robots is malfunctioning! The job of the robot is simple; it should follow a lis ...
- 今年暑假不AC - HZNU寒假集训
今年暑假不AC "今年暑假不AC?" "是的." "那你干什么呢?" "看世界杯呀,笨蛋!" "@#$%^&a ...
- FatMouse' Trade -HZNU寒假集训
FatMouse' Trade FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the wa ...
- 畅通工程-HZNU寒假集训
畅通工程 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只 ...
- 并查集模板题(The Suspects )HZNU寒假集训
The Suspects Time Limit: 1000MS Memory Limit: 20000KTotal Submissions: 36817 Accepted: 17860 Descrip ...
- HDOJ 1051. Wooden Sticks 贪心 结构体排序
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- POJ 1065 Wooden Sticks
Wooden Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16262 Accepted: 6748 Descri ...
- HDU ACM 1051/ POJ 1065 Wooden Sticks
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 1051 Wooden Sticks
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
随机推荐
- 1034. Head of a Gang (30) -string离散化 -map应用 -并查集
题目如下: One way that the police finds the head of a gang is to check people's phone calls. If there is ...
- Oracle开发环境搭建
一.软件准备 地址:oracle官网 安装包:因为个人学习用,所以就安装服务器端就可以了,不需要客户端. 一共两个压缩文件,解压时一起解压到到一个文件夹. 本人使用的:win32_11gR2_data ...
- Java中的五种单例模式
Java模式之单例模式: 单例模式确保一个类只有一个实例,自行提供这个实例并向整个系统提供这个实例. 特点: 1,一个类只能有一个实例 2 自己创建这个实例 3 整个系统都要使用这个实例 例: 在下面 ...
- numpy教程:逻辑函数Logic functions
http://blog.csdn.net/pipisorry/article/details/48208433 真值测试Truth value testing all(a[, axis, out, k ...
- 学习pthreads,给线程传递多个参数
上篇博文中,boss线程给其他线程传递的只有一个参数,那么假如是多个参数呢?怎么传递呢?或许你会有这样的疑问,带着这个疑问,我们进入本文的世界,这里传递多个参数,采用结构体,为什么呢?因为结构体里可以 ...
- Android的内存分配与回收
想写一篇关于android的内存分配和回收文章的想法来源于追查一个魅族手机图片滑动卡顿问题,我们想了很多办法还是没有避免他不停的GC,所以就打算详细的看看内存分配和GC的原理,为什么会不断的GC,GC ...
- 目前调试移动设备程序只能通过USB线缆
就像iOS,转移(到设备上)并调试App不可能通过WiFi或蓝牙连接. 一个有线的USB线缆连接现今主要用来调试. 确保你直接将Android设备插入Mac的USB接口,避免使用USB hubs和扩展 ...
- 新书《Ext JS 4.2实战》即将出版
目录: 第1章 Ext JS 4概述1.1 从Ext JS 4.0到4.071.2 从4.1到4.1.1a1.3 从4.2到4.2.11.4 如何选择版本1.5 基 ...
- OC语言(三)
十九.一些规范 import系统自带的用尖括号<>来包含. 发现需求不清晰,一定要先搞明白才去做. 多文件开发,文件名和类名一致 命令行里的做法:(只是编译链接主文件,但是全部编译链接会出 ...
- TCP 的那些事儿(上)(转)
本文转载自陈皓博文TCP 的那些事儿(上). TCP是一个巨复杂的协议,因为他要解决很多问题,而这些问题又带出了很多子问题和阴暗面.所以学习TCP本身是个比较痛苦的过程,但对于学习的过程却能让人有很多 ...