A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is measured as an integral number of time units starting from the moment the sale begins. Each product takes precisely one unit of time for being sold. A selling schedule is an ordered subset of products Sell ≤ Prod such that the selling of each product x∈Sell, according to the ordering of Sell, completes before the deadline dx or just when dx expires. The profit of the selling schedule is Profit(Sell)=Σ x∈Sellpx. An optimal selling schedule is a schedule with a maximum profit. 
For example, consider the products Prod={a,b,c,d} with (pa,da)=(50,2), (pb,db)=(10,1), (pc,dc)=(20,2), and (pd,dd)=(30,1). The possible selling schedules are listed in table 1. For instance, the schedule Sell={d,a} shows that the selling of product d starts at time 0 and ends at time 1, while the selling of product a starts at time 1 and ends at time 2. Each of these products is sold by its deadline. Sell is the optimal schedule and its profit is 80. 

Write a program that reads sets of products from an input text file and computes the profit of an optimal selling schedule for each set of products. 

Input

A set of products starts with an integer 0 <= n <= 10000, which is the number of products in the set, and continues with n pairs pi di of integers, 1 <= pi <= 10000 and 1 <= di <= 10000, that designate the profit and the selling deadline of the i-th product. White spaces can occur freely in input. Input data terminate with an end of file and are guaranteed correct.

Output

For each set of products, the program prints on the standard output the profit of an optimal selling schedule for the set. Each result is printed from the beginning of a separate line.

Sample Input

4  50 2  10 1   20 2   30 1

7  20 1   2 1   10 3  100 2   8 2
5 20 50 10

Sample Output

80
185

Hint

The sample input contains two product sets. The first set encodes the products from table 1. The second set is for 7 products. The profit of an optimal schedule for these products is 185.
 
 
 
题目大意是买卖N件东西,每件东西都有个截止时间,在截止时间之前买都可以,
而每个单位时间只能买一件。问最大获利。
这题是一个贪心水题,进行价格排序,如果当天已经被选则推至前一天 
 
 
 #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cctype>
using namespace std;
struct node
{
int x,y;
}qu[];
int vis[];
int cmp(node a,node b) {
return a.x>b.x;
}
int main() {
int n;
while(scanf("%d",&n)!=EOF){
memset(vis,,sizeof(vis));
for (int i= ;i<n ;i++)
scanf("%d%d",&qu[i].x,&qu[i].y);
sort(qu,qu+n,cmp);
int temp=,sum=;
for (int i= ;i<n ;i++){
if (vis[qu[i].y]==) {
vis[qu[i].y]=;
sum+=qu[i].x;
}else {
for (int j=qu[i].y- ;j>= ;j--){
if (vis[j]==) {
sum+=qu[i].x;
vis[j]=;
break;
}
}
}
}
printf("%d\n",sum);
}
return ;
}
 

Supermarket POJ - 1456的更多相关文章

  1. (并查集 贪心思想)Supermarket -- POJ --1456

    链接: http://poj.org/problem?id=1456 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...

  2. Day5 - H - Supermarket POJ - 1456

    A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold ...

  3. Supermarket POJ - 1456 贪心+并查集

    #include<iostream> #include<algorithm> using namespace std; const int N=1e5; struct edge ...

  4. Supermarket POJ - 1456(贪心)

    题目大意:n个物品,每个物品有一定的保质期d和一定的利润p,一天只能出售一个物品,问最大利润是多少? 题解:这是一个贪心的题目,有两种做法. 1 首先排序,从大到小排,然后每个物品,按保质期从后往前找 ...

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

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

  6. POJ 1456——Supermarket——————【贪心+并查集优化】

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

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

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

  8. poj 1456 Supermarket - 并查集 - 贪心

    题目传送门 传送点I 传送点II 题目大意 有$n$个商品可以销售.每个商品销售会获得一个利润,但也有一个时间限制.每个商品需要1天的时间销售,一天也只能销售一件商品.问最大获利. 考虑将出售每个物品 ...

  9. POJ 1456 Supermarket(贪心+并查集)

    题目链接:http://poj.org/problem?id=1456 题目大意:有n件商品,每件商品都有它的价值和截止售卖日期(超过这个日期就不能再卖了).卖一件商品消耗一个单位时间,售卖顺序是可以 ...

随机推荐

  1. 使用xUnit为.net core程序进行单元测试(4)

    第1部分: http://www.cnblogs.com/cgzl/p/8283610.html 第2部分: http://www.cnblogs.com/cgzl/p/8287588.html 第3 ...

  2. win7下MySQL的安装配置及卸载 笔记分享

    一.官网下载地址:https://dev.mysql.com/downloads/mysql/ 1.选择对应版本,下载免安装版: 2.不要注册账号,点击"No thanks,just sta ...

  3. struct stat结构体简介

    在使用这个结构体和方法时,需要引入: <sys/types.h> <sys/stat.h> struct stat这个结构体是用来描述一个linux系统文件系统中的文件属性的结 ...

  4. Halcon一日一练:CAD类型的相关操作

    大很多场合,需要在视觉程序中导入CAD文档,比如,在3C行业,需要对手机外壳进行CNC加工,或者点胶操作,此时,需要获取产品的各个点的数据.如果将CAD直接导入,就会大的减少编程工作量,同时也能达到很 ...

  5. golang使用http client发起get和post请求示例

    [转自 http://www.01happy.com/golang-http-client-get-and-post/ ] get请求 get请求可以直接http.Get方法,非常简单. 1 2 3 ...

  6. word在页眉中插入页码

    编辑页眉时,插入-页码-当前位置-普通数字

  7. 对html语义化的理解

    所有人都知道html即超文本标记语言或超文本链接标示语言,是目前网络上应用最为广泛的语言,也是构成网页文档的主要语言. html标签中的大部分都是由"语义化"标签所担任 那么,它有 ...

  8. Java面试题库及答案解析

    1.面向对象编程(OOP)有哪些优点? 代码开发模块化,更易维护和修改. 代码复用. 增强代码的可靠性和灵活性. 增加代码的可理解性. 2.面向对象编程有哪些特性? 封装.继承.多态.抽象 封装 封装 ...

  9. 1.12 dict 字典表

    dict 字典表属于映射分类 dict的声明 >>> #dict类型 是 {}中包含若干个键值对 >>> d = dict() >>> d = { ...

  10. LeetCode第六天

    第六天 30.(219) Contains Duplicate II JAVA class Solution { public boolean containsNearbyDuplicate(int[ ...