当前位置:网站首页>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;
}
边栏推荐
- Twin all things digital visual | join the real world and the digital space
- MySQL外键约束怎么创建
- CAS原理以及ABA问题解决Demo-代码
- 面试突击69:TCP 可靠吗?为什么?
- 闻泰科技拟收购欧菲光摄像头业务资产,或将进入苹果供应链!
- 什么时候使用UserCF,什么时候使用ItemCF?
- 面试官:MySQL如何根据执行计划调优SQL语句?
- 【高并发】我用多线程进一步优化了亿级流量电商业务下的海量数据校对系统,性能再次提升了200%!!(全程干货,建议收藏)
- Tech Talk 活动回顾|基于 Amazon KVS 打造智能视觉产品
- 木棒
猜你喜欢

leetcode:1901. 寻找峰值 II【二分找矩阵局部最大】

阅读顺序

ByteArrayOutputStream class source code analysis

最新!多交的税可以退,同学,你今天退税了吗?

GBJ2510-ASEMI电机专用25A整流桥GBJ2510

query词权重, 搜索词权重计算

如何在C语言中定义自己的数据类型?

(notes) Build the was configured to -- Settings repositories over project repositories but solutions

Flutter动态化 | Fair 2.6.0 新版本特性

支持百亿请求的微博广告运维技术实践
随机推荐
面试官:小伙子你来说说MySQL底层架构设计
知识图谱构建全流程
MLX90640 infrared thermal imager development notes (9)
tcp的四次挥手(为什么三次握手和四次挥手)
召回 i2i
Practice of Weibo Advertising Operation and Maintenance Technology Supporting Ten Billions of Requests
CRM如何帮助企业营销获客
旭硝子龟尾工厂3月起将减少30%玻璃基板供应!TCL华星、友达、群创、惠科均受影响
参加Ultimate Harvest Moon活动,立即赢取终极版月光女神NFT
Staggered question explanation
Tech Talk 活动回顾|基于 Amazon KVS 打造智能视觉产品
【Leetcode】200. 岛屿数量(中等)
pjax无法生效解决办法,butterfly主题维护你的pjax
Turbine Aggregation Monitoring
干货!如何使用仪表构造SRv6-TE性能测试环境
揭秘 | 2019 To B 年度盛宴那些人和那些事
【微信小程序】零基础学 | 小程序语法
[极客大挑战 2019]BabySQL 1
HMS Core音频编辑服务音源分离与空间音频渲染,助力快速进入3D音频的世界
STC8h1k28六个基本实验