当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
Automated win training script log
Dry goods!How to Construct SRv6-TE Performance Test Environment Using Instrumentation
Talking about the memory layout of the program
#夏日挑战赛# HarmonyOS - 实现签名功能
sorting and searching 二分查找法
Tech Talk 活动回顾|基于 Amazon KVS 打造智能视觉产品
最新!多交的税可以退,同学,你今天退税了吗?
LinkedList 5-141. The circular linked list
win10 校验sha256
如何在C语言中定义自己的数据类型?
应用程序间的数据传输TCP协议的特点及
zabbix email sends alert information
可行性研究报告模板
美国对集成电路及其产品发起337调查:英特尔/联想/宏碁/华硕/微星均涉及其中
58安全-图像质量评价技术实践
[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
溢价20%,瑞萨电子宣布拟以60亿美元收购Dialog
掘金量化:通过history方法获取数据,和新浪财经,雪球同用等比复权因子。不同于同花顺
718. The longest repeat subarray
Easy Genes: Human tRNA loci exhibit DNA hypermethylation associated with aging | Research Article






![[Designers must learn] Lighting skills of Enscape in SketchUp](/img/98/0b4e5241774f03141ef1c918707d86.jpg)
