当前位置:网站首页>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;
}
边栏推荐
- 两军交锋
- CAS原理以及ABA问题解决Demo-代码
- Twin all things digital visual | join the real world and the digital space
- RocketQA: across batches negative sampling (cross - batch negatives), the denoising of strong negative cases of sampling (denoised hard negative from) and data to enhance (data augment
- ByteArrayOutputStream 类源码分析
- Automated win training script log
- 旭硝子龟尾工厂3月起将减少30%玻璃基板供应!TCL华星、友达、群创、惠科均受影响
- RocketQA:通过跨批次负采样(cross-batch negatives)、去噪的强负例采样(denoised hard negative sampling)与数据增强(data augment
- 浅聊对比学习(Contrastive Learning)
- Go语言结构体Go range怎么使用
猜你喜欢
随机推荐
ByteArrayOutputStream class source code analysis
Rust P2P网络应用实战-1 P2P网络核心概念及Ping程序
面试突击69:TCP 可靠吗?为什么?
浅聊对比学习(Contrastive Learning)
MUD DAO火爆入世,DAO主轮募集蓄势待发
干货!如何使用仪表构造SRv6-TE性能测试环境
兆易创新2021年将从长鑫存储采购3亿美元DRAM产品
设置工作模式与环境
【PCL学习笔记】点云处理常用的库和API(PCL库+Eigen)
ByteArrayOutputStream 类源码分析
华虹半导体四季度营收再创历史新高,同比增长15.4%
接口内容01文档:postman学习路线
接口项目02文档:Jmeter接口测试与性能测试
Tutorial/detailed_workflow. Ipynb quantitative financial Qlib library
动态规划 爬楼梯
Loadrunner与Jmeter区别与相同
58安全-图像质量评价技术实践
阶乘因式分解
2020年Mobileye收入近10亿美元,EyeQ芯片出货1930万颗
Go语言结构体Go range怎么使用