There is a pile of n wooden sticks. The length and weight ofeach stick are known in advance. The sticks areto be processed by a woodworking machine in one by one fashion. Itneeds some time, called setup time, forthe machine to prepare
processing a stick. The setup times areassociated with cleaning operations andchanging tools and shapes in the machine. The setup times of thewoodworking machine are given as follows:
- The setup time for the first woodenstick is 1 minute.
- Right after processing a stick of length l and weight w, the machine will need no setup time for a stickof lengthl' 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
nwooden sticks. For example, if you havefive sticks whose pairs of length and weight are (4,9), (5,2), (2,1), (3,5),and (1,4) then the minimum setuptime should be 2 minutes since there
is a sequence of pairs (1,4),(3,5), (4,9), (2,1), (5,2).
The input consists of
T test cases. The number of test cases (
T) is given in the first line of the input file. Eachtest case consists of two lines: The first line has an integer
n,1<=
n<=5000, that represents the number ofwooden
sticks in the test case, and the second line contains 2
npositiveintegers
l1,
w1,
l2,
w2, ...,
ln,
wn,each of magnitude at most 10000, where
li
and
wiare the length and weight of the
i th wooden stick,respectively. The 2
n
integers are delimited by one ormore spaces.
The output should contain the minimum setup time in minutes, one perline.
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
题意:
有点说不清楚, 我简单点说就是排序, 拿样例的第一组来说
我们要做到: 下一根木棍的长度l和重量w 都要比 当前根来的大
看第一组样例最后排成的序列 (1,4),(3,5),(4,9),(2.1),(5.2)
显然前三个木棍是符合要求的, 然后(4,9) 和 (2,1) 明显不符合要求, 那么就停止, 前三根木棍算重新设置了一下, 编成了一组
然后 将(2,1),(5,2)再继续设置, 如此往复, 求最少设置了几次~?
做法:
按长度从小到大排序, 若长度相同, 则按重量从小到大排序(先按重量再按长度也行)
然后, 我们针对当前木棍, 与剩下的木棍比较, 满足 w1 <= w2 && l1 <= l2 的, 就更新一下当前棍, 并标记~
当所有木棍都被编组后 输出到底设置了几次~
AC代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct Point{
int l;
int w;
int mark;
}point[5555];
int cmp(Point a, Point b) {
if(a.l != b.l)
return a.l < b.l;
return a.w <= b.w;
}
int main() {
int T;
scanf("%d", &T);
while(T--) {
int n;
scanf("%d", &n);
int time = 0;
memset(point, 0, sizeof(point));
for(int i = 0; i < n; i++)
scanf("%d %d", &point[i].l, &point[i].w);
sort(point, point+n, cmp);
int tmp;
for(int i = 0; i < n; i++) {
if(point[i].mark)
continue;
time++;
tmp = point[i].w;
for(int j = i; j < n; j++) {
if(point[j].w >= tmp && point[j].mark == 0) {
tmp = point[j].w;
point[j].mark = 1;
}
}
}
printf("%d\n", time);
}
return 0;
}
相关推荐
安国Alcor AU6983量产工具V090409(支持34NM)
sBotClass ... 埃斯基13.08.2014güncellemesindenöncekisürümlerdewp-content / uploads / images dizini olmakzorundadır。 Dikkat(当心!) Tr:下载adverten重新下载edip onuöneçıkarılm
OneKeyTools10-五周年纪念最终版[SP13.08](仅支持PowerPoint) PPT好用工具
型号 额定功率(W) 稳定电压(V) 稳定电流(A) ...12.4~13.08 0.005 RLJZ3.6B O.4 3.55~3.8 0.005 RLJz6.8C 0.4 6.82~7.2 0.005 RLJZ13B 0.4 12.88~13.57 0.005 RLJZ3.
魔法师支票票据打印软件系统用于各类支票打印、进帐单打印、电汇凭证打印、现金交款单打印和业务委托书与业务申请书打印,帮助财务人员减轻日常票据填写工作,并有效避免填写错误。本打印软件是一款具备全自主创建...
学习使用atmega128的Boot Loader功能 实现一个世纪的boot loader程序 程序清单 ...hexbin.exe 13.08 KB main.c 7.31 KB readme.txt 451 bytes TEST.BIN 300 bytes test.hex 860 bytes
改性焦粉吸附亚甲基蓝焓变为43.33 kJ/mol,自由能变在-13.08~-8.46 kJ/mol之间,熵变在0.018~0.041 kJ/mol之间;黏附几率S=5.943×10-9,活化能为41.11 kJ/mol,表明该吸附过程是界面上混乱度增加的自发吸热过程;吸附过程...
全国支票影像交换系统架构介绍:全国支票影像交换系统(影像交换系统)是指综合运用影像技术和支付密码等技术,将纸质支票转化为影像和电子信息,实现纸质支票截留,利用信息网络...实现支票全国通用的业务处理系统。
13.08.2008 AlphaControls v5.62 beta released * Improved design-time editor for the SkinManager.ThirdParty property * Fixed known errors in TsScrollBox, TsTabControl and TsPageControl components * ...
对照组的青春期男孩(平均知识得分为15.35,标准偏差±4.748)在干预后明显高于女性(平均得分为13.08,标准偏差±4.325)(P = 0.009)。 在干预组中,干预后3个月对艾滋病毒/艾滋病有良好知识和良好态度的受访者...
开始安装6点击Finish安装完成,点击Finish7替换破解文件断网,右击桌面快捷方式→属性→打开文件位置,打开软件根目录,将破解补丁复制替换,默认目录:C:\Program Files\ACD Systems\ACDSee Pro\13.08运行注册文件...
结果表明:常温下氧浓度在13.08%时,煤样仍能够发生氧化;风量越小,氧浓度越低,CO气体浓度越高;工作面供风量减小,导致采空区出现CO气体浓度增大,停采时间越长,采空区CO气体浓度越大,但是并不能证明采空区温度有上升趋势...
菲斯金卡德 根据检测文本的等级级别的公式。 见用于检测音节。安装该软件包仅适用于ESM:需要使用Node 12+才能使用它...{ sentence : 1 , word : 13 , syllable : 26 } )// => 13.08原料药该软件包导出以下标识符: fle
结果表明:无论5月和9月,随着生长光强的降低,苦槠幼苗叶片的最大净光合速率、光补偿点和光饱和点均有减小的趋势,尤其在9月,在15%自然光强下分别为13.08Vmol・m-2・s-1,962umolm-Zs-1,198.80协mol・m-2・s-1,显著...
为探讨He-Ne激光对紫外线-B(UV-B)辐射损伤修复途径,采用He-Ne激光辐照(5 mW·mm-2)进行照射,对增强UV-B(13.08 kJ·m-2·d-1)辐射下水稻幼苗的叶绿素含量、核酮糖-1,5-二磷酸羧化酶/加氧酶(rubisco)亚基含量及反映...