K.Deadline There are N bugs to be repaired and some engineers whose abilities are roughly equal. And an engineer can repair a bug per day. Each bug has a deadline A[i].

Question: How many engineers can repair all bugs before those deadlines at least? 1<=n<= 1e6. 1<=a[i] <=1e9

Input Description There are multiply test cases. In each case, the first line is an integer N , indicates the number of bugs. The next line is n integers indicates the deadlines of those bugs.

Output Description There are one number indicates the answer to the question in a line for each case.

Input 4 1 2 3 4

Output 1

排序,大于N的不用考虑,否则超时

贪心

 #include <bits/stdc++.h>
using namespace std; const int MAXN = 1e6 + ; int a[MAXN];
int b[MAXN];
int tot; int main()
{
int n;
int i;
int j;
int maxB;
int lMaxB; while (~scanf("%d", &n)) {
int n2 = n;
for (i = ; i < n; ++i) {
scanf("%d", &a[i]);
if (a[i] >= n2) {
--i;
--n;
}
}
//cout << n << endl;
sort(a, a + n); tot = ;
b[tot++] = ;
for (i = ; i < n; ++i) {
maxB = -;
for (j = ; j < tot; ++j) {
if (b[j] < a[i] && b[j] > maxB) {
maxB = b[j];
lMaxB = j;
break;
}
} if (maxB == -) {
b[tot++] = ;
} else {
++b[lMaxB];
} } printf("%d\n", tot);
} return ;
}

但是为什么用set写超时呢,不是应该比数组遍历查找要快吗?

超时代码:

 #include <bits/stdc++.h>
using namespace std; const int MAXN = 1e6 + ; int a[MAXN]; struct cmp {
bool operator()(int a, int b)
{
return a > b;
}
};
multiset<int, cmp> st; int main()
{
int n;
int i;
multiset<int, cmp>::iterator it;
int tmp; while (~scanf("%d", &n)) {
st.clear();
int n2 = n;
for (i = ; i < n; ++i) {
scanf("%d", &a[i]);
if (a[i] >= n2) {
--i;
--n;
}
}
//cout << n << endl;
sort(a, a + n); st.insert();
for (i = ; i < n; ++i) {
it = st.upper_bound(a[i]);
if (it == st.end()) {
st.insert();
} else {
tmp = *it + ;
st.erase(it);
st.insert(tmp);
}
} printf("%d\n", st.size()); } return ;
}

其实这题可以用 任务数 / 天数,向上取整得到最少需要的人数,取最大值

 #include <bits/stdc++.h>
using namespace std; const int MAXN = 1e6 + ; int maxA;
int b[MAXN];//b[i]保存当天要完成的任务数
int sum[MAXN];//sum[i]代表之前一共要完成任务数 int main()
{
int n;
int i;
int a;
int ans; while (~scanf("%d", &n)) { memset(b, , sizeof(b));
for (i = ; i < n; ++i) {
scanf("%d", &a);
if (a > n) {
continue;
}
++b[a];
if (a > maxA) {
maxA = a;
}
}
//cout << n << endl; sum[] = ;
ans = ;//最小为1个工人...//初始化为0不对。因为有可能所有日期都大于n,那么结果应该为1,而不是0
for (i = ; i <= maxA; ++i) {
sum[i] = sum[i - ] + b[i];
ans = max(ans, (sum[i] + i - ) / i);
} printf("%d\n", ans);
} return ;
}

hzau 1209 Deadline(贪心)的更多相关文章

  1. HZAU 18——Array C——————【贪心】

    18: Array C Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 586  Solved: 104[Submit][Status][Web Boar ...

  2. POJ 1456(贪心)

    #include <string.h> #include <iostream> #include <queue> #include <stdio.h> ...

  3. POJ 1456 Supermarket 区间问题并查集||贪心

    F - Supermarket Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Sub ...

  4. BZOJ_1620_[Usaco2008_Nov]_Time_Management_时间管理_(二分+贪心)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1620 N个工作,每个工作其所需时间,及完成的Deadline,问要完成所有工作,最迟要什么时候 ...

  5. [BZOJ 1029] [JSOI2007] 建筑抢修 【贪心】

    题目链接:BZOJ - 1029 题目分析 使用一种贪心策略. 现将任务按照deadline从小到大排序. 然后枚举每一个任务,如果当前消耗的时间加上完成这个任务的时间不会超过这个任务的deadlin ...

  6. HDU 1789 Doing Homework again(贪心)

    在我上一篇说到的,就是这个,贪心的做法,对比一下就能发现,另一个的扣分会累加而且最后一定是把所有的作业都做了,而这个扣分是一次性的,所以应该是舍弃扣分小的,所以结构体排序后,往前选择一个损失最小的方案 ...

  7. hdu--1798--Doing Homework again(贪心)

    Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  8. POJ-1456 Supermarket 销售商品【贪心】+【并查集】

    题目链接:http://poj.org/problem?id=1456 题目大意: 有N件商品,分别给出商品的价值和销售的最后期限,只要在最后日期之前销售处,就能得到相应的利润,并且销售该商品需要1天 ...

  9. POJ 1456 - Supermarket - [贪心+小顶堆]

    题目链接:http://poj.org/problem?id=1456 Time Limit: 2000MS Memory Limit: 65536K Description A supermarke ...

随机推荐

  1. Nuxt使用element-ui

    废话不多说,在Nuxt中引入Nuxt其实很简单,分下面几步 一.安装element-ui依赖 打开nuxt项目以后,在Terminal中通过 npm i element-ui -S 即可安装eleme ...

  2. 洛谷 P1640 [SCOI2010]连续攻击问题

    洛谷 一句话题意: 每个武器有两种属性,每种武器只能选择一种属性,从属性1连续递增才算攻击,求最大连续攻击次数. 因为同学告诉我这是二分图最大匹配,自然就往那个方向去想. 那么怎么建图呢? 每个武器只 ...

  3. document.documentElement和document.body区别以及获取浏览器的宽高

    原文:http://www.jb51.net/article/41410.htm 1.区别: body是DOM对象里的body子节点,即 <body> 标签: documentElemen ...

  4. Python学习进程(6)函数

        函数最重要的目的是方便我们重复使用相同的一段程序.     (1)函数的定义: 函数定义的简单规则: 1.函数代码块以 def 关键词开头,后接函数标识符名称和圆括号(): 2.任何传入参数和 ...

  5. Linux Shell编程 sed命令

    概述 sed 是一种几乎可以应用在所有 UNIX 平台(包括 Linux)上的轻量级流编辑器,体积小.所以,它可以对从如管道这样的标准输入中接收的数据进行编辑. sed 主要是用来将数据进行选取.替换 ...

  6. mongodb php 支持

    http://bbs.csdn.net/topics/391931404?page=1 windows下为php7.0.4安装目前官方版本对应的最新的php_mongodb.dll扩展,该扩展版本为1 ...

  7. css float 浮动是个混球

    得说,在学习 CSS 的时候就一直在疑惑,横排布局干嘛要用 float 这种属性, 用了还会高度塌陷,怎么不发明些高级点的属性来完成横排布局呢, 甚至所有人都告诉我摒弃表格布局,浮动布局才是 DIV+ ...

  8. MySQL运维问题集锦

    1.莫名的慢查询问题.解决思路:http://hidba.org/?spm=5176.153233.793262.6.d75LDx&p=1119

  9. Django 路由、模板和模型系统

    一.路由系统 URL配置(URLconf)就像Django 所支撑网站的目录.它的本质是URL模式以及要为该URL模式调用的视图函数之间的映射表:你就是以这种方式告诉Django,对于这个URL调用这 ...

  10. React-Native Listview组件用法详解

    ListView作为React Native的核心组件,用于高效地显示一个可以垂直滚动的变化的数据列表.其中最重要的属性之一是DataSource,列表依赖的数据源,用于实例化一个ListView对象 ...