当前位置:网站首页>wooden stick
wooden stick
2022-07-29 17:14:00 【Seal the son ink】
木棒
时间限制: 1 Sec 内存限制: 32 MB
Title Description Existingn根木棒,已知它们的长度和重量.要用一部木工机一根一根地加工这些木棒.该机器在加工过程中需要一定的准备时间,是用于清洗机器,Adjustment tools and templates.木工机需要的准备时间如下:
(1)第一根木棒需要1min的准备时间;
(2)在加工了一根长为l,重为w的木棒之后,接着加工一根长为ll(l<=ll),重为ww(w<=ww)的木棒是不需要任何准备时间的.否则需要一分钟的准备时间.
给定n根木棒,You want to find the minimum preparation time.例如现在有长和重分别为(4,9),(5,2),(2,1),(3,5)和(1,4)的五根木棒,那么所需准备时间最少为2min,顺序为(1,4),(3,5),(4,9),(2,1),(5,2).Input Input contains sets of test data.输入的第一行是一个整数T,表示测试数据的个数.
每个测试例两行:
第一行是一个整数n(1<=n<=5000),表示有多少根木棒;
第二行包括n*2个整数,表示了l1,w1,l2,w2,l3,w3,…,ln,wn,None of these numbers is greater than 10000,其中li和wi表示第i根木棒的长度和重量.Output Minimum preparation time in minutes for output.样例输入
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样例输出
2
1
3
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef struct stick {
int L;
int W;
int tag;
};
int cmp(stick a,stick b) {
if(a.L==b.L)
return a.W<=b.W;
else
return a.L<=b.L;
}
int main() {
int N;
scanf("%d",&N);
while(N--) {
int M;
scanf("%d",&M);
struct stick sti[M];
for(int i=0; i<M; i++) {
scanf("%d %d",&sti[i].L,&sti[i].W);
sti[i].tag=0;
}
sort(sti,sti+M,cmp);
int sum=0,l,w;
for(int i=0; i<M; i++) {
if(sti[i].tag==0) {
sti[i].tag=1;
sum++;
l=sti[i].L;
w=sti[i].W;
for(int j=0; j<M; j++) {
if(sti[j].tag==0&&sti[j].L>=l&&sti[j].W>=w) {
sti[j].tag=1;
l=sti[j].L;
w=sti[j].W;
}
}
}
}
printf("%d\n",sum);
}
return 0;
}
边栏推荐
- Query term weights, search term weighting
- ASCII码排序
- [网络知识]路由OSPF
- 虚拟远程桌面
- LinkedList 5-141. The circular linked list
- This article penetrates the architecture design and cluster construction of the distributed storage system Ceph (hands-on)
- R语言中给数据框增加分组/根据样本名称添加分组的代码
- [PCL study notes] Commonly used libraries and APIs for point cloud processing (PCL library Eigen)
- 【服务器存储数据恢复】华为OceanStor某型号存储raid5硬盘故障离线,热备盘同步数据失败导致raid崩溃的数据恢复案例
- 分布式前修课:MySQL实现分布式锁
猜你喜欢

大规模线上应用TiDB会遇到的坑,本文都帮你排除好了

递归法解决N皇后问题

MySQL外键约束怎么创建

如何写好设计文档
![[Server Storage Data Recovery] A data recovery case of a RAID 5 crash caused by the failure of a certain model of Huawei OceanStor storage RAID 5 hard disk and the failure to synchronize data with the](/img/86/b664e56dff66c57c9f24c850919743.png)
[Server Storage Data Recovery] A data recovery case of a RAID 5 crash caused by the failure of a certain model of Huawei OceanStor storage RAID 5 hard disk and the failure to synchronize data with the

贪心(1)区间完全覆盖问题

面试突击69:TCP 可靠吗?为什么?

重磅来袭!豆瓣评分9.9,万人血书的多线程与高并发v2.0版本

718. 最长重复子数组

This article penetrates the architecture design and cluster construction of the distributed storage system Ceph (hands-on)
随机推荐
什么时候使用UserCF,什么时候使用ItemCF?
[C语言刷题篇]链表运用讲解
再见Postman!一款更适合国人的接口管理工具
ASCII码排序
Sorting and searching binary search method
Interviewer: What are the design principles?What is the Lie Substitution Principle?
CAS原理以及ABA问题解决Demo-代码
LinkedList 5-141. 环形链表
溢价20%,瑞萨电子宣布拟以60亿美元收购Dialog
接口项目02文档:Jmeter接口测试与性能测试
[网络知识]交换STP
【地形】【虚拟纹理】地形虚拟纹理技术介绍
【微信小程序】组件使用及属性参考
ByteArrayOutputStream class source code analysis
上海移动基于亚信科技AntDB完成核心账务数据库的国产化替换
自动化win训练脚本+日志
LinkedList 5-141. The circular linked list
揭秘 | 2019 To B 年度盛宴那些人和那些事
华虹半导体四季度营收再创历史新高,同比增长15.4%
大数阶乘计算