poj 2786 - Keep the Customer Satisfied
Description
Simon and Garfunkel Corporation (SG Corp.) is a large steel-making company with thousand of customers. Keeping the customer satisfied is one of the major objective of Paul and Art, the managers.
Customers issue orders that are characterized by two integer values q<tex2html_verbatim_mark> , the amount of steel required (in tons) and d<tex2html_verbatim_mark> , the due date (a calender date converted in seconds). The due date has to be met if SG Corp. accepts the order. Stated another way, when an order is accepted, the corresponding amount of steel has to be produced before its due date. Of course, the factory can process no more than one order at a time.
Although the manufacturing process is rather complex, it can be seen as a single production line with a constant throughput. In the following, we assume that producing q<tex2html_verbatim_mark> tons of steel takes exactly q<tex2html_verbatim_mark> seconds (i.e., throughput is 1). The factory runs on a monthly production plan. Before the beginning of the month, all customers' orders are collected and Paul and Art determine which of them are going to be accepted and which ones are to be rejected in the next production period. A production schedule is then designed. To keep customers satisfied, Paul and Art want to minimize the total number of orders that are rejected. In the following, we assume that the beginning of the next production plan (i.e., the first day of the next month) corresponds to date 0.
Hogdson and Moore have been appointed as Chief Scientific Officers and you are requested to help them to compute an optimal solution and to build a schedule of all accepted orders (starting time and completion time).
Small Example
Consider the following data set made of 6 orders J1,..., J6<tex2html_verbatim_mark> . For a given order, Jj<tex2html_verbatim_mark> , qj<tex2html_verbatim_mark> denotes the amount of steel required and dj<tex2html_verbatim_mark> is the associated due date.
Order | qj<tex2html_verbatim_mark> | dj<tex2html_verbatim_mark> |
J1<tex2html_verbatim_mark> | 6 | 8 |
J2<tex2html_verbatim_mark> | 4 | 9 |
J3<tex2html_verbatim_mark> | 7 | 15 |
J4<tex2html_verbatim_mark> | 8 | 20 |
J5<tex2html_verbatim_mark> | 3 | 21 |
J6<tex2html_verbatim_mark> | 5 | 22 |
You can check by hand that all orders cannot be accepted and it's very unlikely you could find a solution with less than two rejected orders. Here is an optimal solution: Reject J1<tex2html_verbatim_mark> and J4<tex2html_verbatim_mark> , accept all other orders and process them as follows.
Accepted Order | Starting Time | Completion Time |
J2<tex2html_verbatim_mark> | 0 | 4 |
J3<tex2html_verbatim_mark> | 4 | 11 |
J5<tex2html_verbatim_mark> | 11 | 14 |
J6<tex2html_verbatim_mark> | 14 | 19 |
Note that the production line is never idle.
Input
The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.
Data Each test case is described by one input file that contains all the relevant data: The first line contains the number n<tex2html_verbatim_mark> of orders ( n<tex2html_verbatim_mark>can be as large as 800000 for some test cases). It is followed by n<tex2html_verbatim_mark> lines. Each of which describes an order made of two integer values: the amount of steel (in tons) required for the order (lower than 1000) and its due date (in seconds; lower than 2 x 106<tex2html_verbatim_mark> ).
Output
For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.
You are required to compute an optimal solution and your program has to write the number of orders that are accepted.
Sample Input
1 6
7 15
8 20
6 8
4 9
3 21
5 22
Sample Output
4
题意: SG公司, 要安排客户的钢铁订单, 给出订单量和订单截止日期 现在要求你帮他们计算出尽可能的安排多的订单经行生产, 无法完成的订单只能放弃, 计算出可以完成最大的订单数量.
先排序,限期紧的放在前面,一直接订单,如果超过期限,去掉任务领大的,因为要求订单最多,所以任务轻的定单优先,所以用priority_queue;
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std; priority_queue<int> qu;
struct node
{
int q, d;
bool operator <(const node &x) const{
return d < x.d;
}
}a[];
int n;
int main()
{
int t;scanf("%d",&t);
int x=;
while(t--)
{
if(x++!=)puts("");
scanf("%d", &n);
for(int i = ; i <= n; ++i)scanf("%d %d", &a[i].q, &a[i].d); sort(a+, a++n); while(!qu.empty())qu.pop(); int ans=n; int ti=; for(int i=; i <= n; ++i)
{
ti += a[i].q;
qu.push(a[i].q);
if(ti > a[i].d){
ti -= qu.top();
qu.pop();
ans--;
}
}
printf("%d\n", ans);
}
return ;
}
poj 2786 - Keep the Customer Satisfied的更多相关文章
- UVA - 1153 Keep the Customer Satisfied(贪心)
UVA - 1153 Keep the Customer Satisfied Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: ...
- UVA1153-Keep the Customer Satisfied(贪心)
Problem UVA1153-Keep the Customer Satisfied Accept: 222 Submit: 1706Time Limit: 3000 mSec Problem D ...
- UVa 1153 Keep the Customer Satisfied 【贪心 优先队列】
题意:给出n个工作,已知每个工作需要的时间last,以及截止时间end,(必须在截止时间之前完成)问最多能够完成多少个工作 首先预处理,将这n件任务按照截止时间从小到大排序 然后用一个cur记录当前做 ...
- Keep the Customer Satisfied
题意: n个订单,每个订单有完成需要的天数,和限制的天数,求最多能完成多少订单 分析: 先按限制日期升序排列,若当前订单不能完成,和上面已选中的订单中需要天数中最大的比较,若比它小,则替换他. #in ...
- UVA 1153 KEEP THE CUSTOMER SATISFIED
题意: 钢铁公司有N个客户的订单,每个订单有一个产量q(生产时间刚好也等于q)和订单完成截止时间.公司要求完成尽量多的订单. 分析: 先按截止时间d排序,然后维护一个已经选好的订单的优先队列,如果当前 ...
- UVALive - 3507 Keep the Customer Satisfied
题意:收到n个订单,每个订单有q,d分别代表做这个的时间,和最晚的完成时间,问你最多能接受几个订单 思路:贪心,我们显然要按最早的完成时间排序,那么接下来,我们用(6,8)和(4,9)做为例子,按照我 ...
- UVA-1153 Keep the Customer Satisfied (贪心)
题目大意:有n件工作,做每件工作的消耗时间为s,截止时间为d,问最多能做完几件工作. 题目分析:贪心策略:优先做截止时间靠前的,一旦做不完当前工作,则从已经做过的工作中删去一件耗时最长的,用当前工作取 ...
- UVa 1153 Keep the Customer Satisfied (贪心+优先队列)
题意:给定 n 个工作,已知每个工作要用的时间 q 和 截止时间 d,问你最多完成多少个工作,每次最多能运行一个工作. 析:这个题是贪心,应该能看出来,关键是贪心策略是什么,这样想,先按截止时间排序, ...
- UVALive 3507:Keep the Customer Satisfied(贪心 Grade C)
VJ题目链接 题意: 知道n(n <= 8e6)个工作的完成所需时间q和截止时间d,你一次只能做一个工作.问最多能做多少工作? 思路: 首先很像贪心.观察发现如下两个贪心性质: 1)一定存在一个 ...
随机推荐
- [Swust OJ 842]--实验室和食堂(最短路,Dijkstra算法)
题目链接:http://acm.swust.edu.cn/problem/842/ Time limit(ms): 1000 Memory limit(kb): 10000 Description ...
- 2014 HDU多校弟九场I题 不会DP也能水出来的简单DP题
听了ZWK大大的思路,就立马1A了 思路是这样的: 算最小GPA的时候,首先每个科目分配到69分(不足的话直接输出GPA 2),然后FOR循环下来使REMAIN POINT减少,每个科目的上限加到10 ...
- POJ 2187 旋转卡壳 + 水平序 Graham 扫描算法 + 运算符重载
水平序 Graham 扫描算法: 计算二维凸包的时候可以用到,Graham 扫描算法有水平序和极角序两种. 极角序算法能一次确定整个凸包, 但是计算极角需要用到三角函数,速度较慢,精度较差,特殊情况较 ...
- jQuery如何设置自增自减值
一直不是很记得jquery中怎么设置自增值,比如当点击按钮时 div在当前宽度基础上增加宽度100px,可以这样写: $('button.test').click(function(){ $('div ...
- ring0和ring3的区别
现在探讨内核程序和应用程序之间的本质区别.除了能用WDK编写内核程序和阅读一部分Windows的内核代码之外,我们还需要了解它们的本质是什么,它们和我们熟悉的应用程序有什么区别. Intel的x86处 ...
- Git学习笔记总结和注意事项
一.Git简单介绍 Git是眼下世界上最先进的分布式版本号控制系统.其特点简单来说就是:高端大气上档次! 二.Windows上Git安装 最早Git是在Linux上开发的.非常长一段时间内.Git也仅 ...
- xp每天定时关机命令
at 00:00 /every:M,T,W,Th,F,S,Su shutdown -s -t 120 能够把00:00改成你想要每天定时关机的时间,120是指关机倒计时的秒数,也能够更改 M,T,W, ...
- 1 #安装php
#安装php #备注:php5..3以后的版本源码不需要打php-fpm补丁,该补丁已经集成进5..3中强制启用fastcgi. [root@dba01 nginx-]# cd [root@dba01 ...
- android 小结
1.layout中的布局文件xml中不能有大写字母. 2.时刻要想着空指针,尤其是安卓5.0后,不报异常,直接ANR.
- VirtualBox安装及使用说明和虚拟机安装XP系统图文教程
virtualbox是一款开源的虚拟机软件,它能够支持多种操作系统的安装如:Solaris.Windows.DOS.Linux.OS/2 Warp.BSD等系统作为client操作系统,而且最新版本号 ...