poj 2786 - Keep the Customer Satisfied

Description

Download as PDF
 

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.

 

Orderqj<tex2html_verbatim_mark>dj<tex2html_verbatim_mark>
J1<tex2html_verbatim_mark>68
J2<tex2html_verbatim_mark>49
J3<tex2html_verbatim_mark>715
J4<tex2html_verbatim_mark>820
J5<tex2html_verbatim_mark>321
J6<tex2html_verbatim_mark>522

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 OrderStarting TimeCompletion Time
J2<tex2html_verbatim_mark>04
J3<tex2html_verbatim_mark>411
J5<tex2html_verbatim_mark>1114
J6<tex2html_verbatim_mark>1419

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 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[800005];
int n;
int main()
{
    int t;scanf("%d",&t);
    int x=1;
 while(t--)
 {
     if(x++!=1)puts("");
        scanf("%d", &n);
      for(int i = 1; i <= n; ++i)scanf("%d %d", &a[i].q, &a[i].d);

      sort(a+1, a+1+n);

      while(!qu.empty())qu.pop();

      int ans=n;  int ti=0;

      for(int i=1; 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 0;
}
View Code

 

转载于:https://www.cnblogs.com/demodemo/p/4716085.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值