心急的C小加

时间限制:1000 ms  |  内存限制:65535 KB
难度:4
 
描述

C小加有一些木棒,它们的长度和质量都已经知道,需要一个机器处理这些木棒,机器开启的时候需要耗费一个单位的时间,如果第i+1个木棒的重量和长度都大于等于第i个处理的木棒,那么将不会耗费时间,否则需要消耗一个单位的时间。因为急着去约会,C小加想在最短的时间内把木棒处理完,你能告诉他应该怎样做吗?

 
输入
第一行是一个整数T(1<T<1500),表示输入数据一共有T组。
每组测试数据的第一行是一个整数N(1<=N<=5000),表示有N个木棒。接下来的一行分别输入N个木棒的L,W(0 < L ,W <= 10000),用一个空格隔开,分别表示木棒的长度和质量。
输出
处理这些木棒的最短时间。
样例输入
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 首先排序,然后在考虑长度的基础上遍历处理掉当前可以处理的并标记,然后继续遍历,遇见没被标记的就cnt++,再次在该点遍历一遍,注意更改当前处理的最大重量
#include<iostream>
#include<cstdio>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<fstream>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAXN 5003
#define INF 1000000009
/*
长度重量都大于当前的 那么无花费
否则花费为1
*/
struct node
{
int w, l;
};
bool cmp(node a, node b)
{
if (a.l == b.l) return a.w < b.w;
return a.l < b.l;
}
node a[MAXN];
bool been[MAXN];
int T, n;
int main()
{
scanf("%d", &T);
while (T--)
{
memset(been, false, sizeof(been));
scanf("%d", &n);
for (int i = ; i < n; i++)
scanf("%d%d", &a[i].l, &a[i].w);
sort(a, a + n, cmp);
int cnt = ;
for (int i = ; i < n; i++)
{
if (!been[i])
{
cnt++;
int tmp = a[i].w;
for (int j = i + ; j < n; j++)
{
if (!been[j] && a[j].w >= tmp)
{
been[j] = true;
tmp = a[j].w;
}
}
}
}
printf("%d\n", cnt);
}
return ;
}

最新文章

  1. PHP清理跨站XSS xss_clean 函数 整理自codeigniter Security
  2. Linux netstat详解
  3. BestCoder10 1002 Revenge of GCD(hdu 5019) 解题报告
  4. 课堂所讲整理:HTML--5JavaScript简介
  5. CODEVS 1036 商务旅行
  6. javascipt学习笔记1
  7. iOS: 获取文件路径
  8. CSS的力量
  9. 优步北京B组(8月10日-8月16日奖励规则)
  10. Spark结构式流编程指南
  11. [最短路][模版]P1346 电车
  12. python scipy计算机数值库
  13. Vmware下centos与windows能ping通并能上网
  14. Invalid property &#39;driver_class&#39; of bean class
  15. [UOJ#207. 共价大爷游长沙]——LCT&amp;随机化
  16. Selenium自动化 Xpath-元素定位
  17. bzoj 3238
  18. BZOJ4381[POI2015]Odwiedziny——分块+长链剖分
  19. python中的函数对象的内存地址是多少
  20. MT【45】抛物线外一点作抛物线的切线(尺规作图题)

热门文章

  1. 倒排索引PForDelta压缩算法——基本假设和霍夫曼压缩同
  2. B1003 物流运输(最短路 + dp)
  3. Spring Boot 打 war 包的步骤
  4. selenium3 + python - page_source页面源码
  5. Linux学习笔记--文件夹结构
  6. es优化收藏
  7. 在窗体中把DataGridView中的数据导出Excel
  8. 【Oracle】 手工建库
  9. JAVA软件工程师应该具备哪些基本素质?
  10. 安卓代码迁移:Program "sh" not found in PATH