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)一定存在一个 ...
随机推荐
- 2080夹角有多大II
寻人启事:2014级新生看过来! 夹角有多大II Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- if…else…if…else…
参见以前做过的练习一元二次方程 #include <stdio.h> #include <math.h> /* 一元二次方程的标准形式:ax2+bx+c=0 a,b,c为常数, ...
- USACO Milk2 区间合并
这题WA了四次,后来发现不能用所谓的桶排来写 虽然空间上是可以的,但是存在这样一个问题 比如两组数据[15,20]和[21,30] 在20 和 21这两个时刻之间没有milking,但是用桶排的方法写 ...
- ASP.NET MVC 5 学习教程:数据迁移之添加字段
原文 ASP.NET MVC 5 学习教程:数据迁移之添加字段 起飞网 ASP.NET MVC 5 学习教程目录: 添加控制器 添加视图 修改视图和布局页 控制器传递数据给视图 添加模型 创建连接字符 ...
- python _thread模块使用
python关于线程管理的有2个类,_thread(在2.x的版本中叫thread)和threading. # encoding: UTF-8 import thread import time ...
- Hadoop 2.x(YARN)安装配置LZO
今天尝试在Hadoop 2.x(YARN)上安装和配置LZO,遇到了很多坑,网上的资料都是基于Hadoop 1.x的,基本没有对于Hadoop 2.x上应用LZO,我在这边记录整个安装配置过程 1. ...
- 基于visual Studio2013解决算法导论之050强连通分支
题目 强连通分支 解决代码及点评 // 强连通分支.cpp : 定义控制台应用程序的入口点. // #include<iostream> #define MAX 100 using ...
- hdu 4975 A simple Gaussian elimination problem.(网络流,推断矩阵是否存在)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4975 Problem Description Dragon is studying math. One ...
- BZOJ 1047: [HAOI2007]理想的正方形( 单调队列 )
单调队列..先对每一行扫一次维护以每个点(x, y)为结尾的长度为n的最大最小值.然后再对每一列扫一次, 在之前的基础上维护(x, y)为结尾的长度为n的最大最小值. 时间复杂度O(ab) (话说还是 ...
- 基于visual Studio2013解决C语言竞赛题之0802图书信息查询
题目 解决代码及点评 /* 功能:有一批图书,每本书有:书名(name),作者(author) , 编号(num),出版日期(date)四个数据, 希望输入后按书名的字母顺序将各书的记录排列好, ...