Supermarket
Supermarket
- 描述
-
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.
- 输入
- 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.
- 输出
- 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.
- 样例输入
-
4 50 2 10 1 20 2 30 17 20 1 2 1 10 3 100 2 8 25 20 50 10
- 样例输出
-
80 185
解题报告:这道题的意思是,每件商品卖出需花费一天时间,只要在截止日期之前(包含)卖出就行。将价值降序,截止日期升序这种方法是不行的。
code:
#include<iostream>
#include<stdio.h>
#include<queue>
#include<vector>
#include<stack>
#include<cstring>
#include<algorithm>using namespace std;typedef long long ll;
const int maxn=10005;
int visited[maxn]; //代表第i天是否有卖商品struct node{int p,d;
};bool cmp(node a,node b){return a.p>b.p;
}int main()
{// freopen("input.txt","r",stdin);int n;while(~scanf("%d",&n)){memset(visited,0,sizeof(visited));node a[maxn]; //存商品for(int i=0;i<n;i++){scanf("%d%d",&a[i].p,&a[i].d);}sort(a,a+n,cmp);int sum=0;for(int i=0;i<n;i++){for(int j=a[i].d;j>=1;j--){ //在截止日期之前卖出就行if(visited[j])continue;visited[j]=1;sum+=a[i].p;break;}}printf("%d\n",sum);}return 0;
}
Supermarket相关推荐
- nyoj 208 Supermarket(贪心)
Supermarket 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 A supermarket has a set Prod of products on sale. ...
- 【并查集】Supermarket(poj 1456/luogu-UVA1316)
Supermarket poj 1456 luogu-UVA1316 题目大意: 有一堆物品,每一件物品都有自己的价值和保质期,每天只能卖出一件物品,问最大价值是多少 原题: 题目描述 有一个商店有许 ...
- CF815C Karen and Supermarket [树形DP]
题目传送门 Karen and Supermarket On the way home, Karen decided to stop by the supermarket to buy some gr ...
- 【POJ - 1456】Supermarket (贪心,优先队列 或并查集)
题干: A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod s ...
- Non-resolvable parent POM for com.supermarket:supermarket:0.0.1-SNAPSHOT: Could not transfer artifac
导入一个maven项目,编译报错 F:\code\supermarket\supermarket>mvn compile [INFO] Scanning for projects... Down ...
- realloc函数UAF利用|攻防世界pwn进阶区supermarket
文章目录 思路 0x00.tar解压 0x01.查看保护 0x02.查看程序并调试 0x03.漏洞分析 realloc函数详解 0x04.利用思路 利用过程 exp-1 解法二 函数须知 0x00.查 ...
- F - Supermarket
F - Supermarket 并查集+贪心( 贪心-> 从高利润的物品开始) #include<string.h> #include<algorithm> #inclu ...
- java farm tycoon_超级市场城农业大亨(Supermarket City : Farm Tycoon)手游官方版v1.0-亿吾手游网...
超级市场城农业大亨(Supermarket City : Farm Tycoon)是一款经营模拟类的手机游戏,在这款游戏中你是一个农场主,你喜欢种植各种蔬菜水果,你需要通过种植各种原材料来开展经营项目 ...
- (POJ - 1456)Supermarket(并查集)
题目链接:1456 -- Supermarket 原题意比较难理解,下面我给出一个简化版的理解方式:超市里有n个商品.第i个商品必须在保质期(第di天及之前)卖掉,若卖掉可让超市获得pi的利润,但是每 ...
最新文章
- android 获取音乐文件的内置专辑图片
- MySQL安装教程,包含所有平台(图解)
- 2.1、spring属性注入-Set方法注入
- ISCC2021 美人计
- 【代码】ReentrantLock使用tryLock进行尝试锁定
- 三足鼎立 —— GPM 到底是什么?(一)
- HDU 3555 Bomb(数位DP模板啊两种形式)
- 机器视觉光源学习总结——平行背光源
- Spring 源码分析(四) ——MVC(六)M 与 C 的实现
- WEB应用中的信息泄漏以及攻击方法
- 小程序中的css样式有哪些,微信小程序中css样式media标签
- HDU 5608 function(莫比乌斯反演 + 杜教筛)题解
- 12306查询车票信息返回的数据解析
- Spigot 算法之一 计算调和级数的和
- 用Axure创建一个知乎登录注册界面
- 数学建模overleaf模板_数学建模从入门到精通必备资料,大神经验助你赢战9月数模国赛!...
- 【mysql】查询中英文名称拼接处理
- BACnet基础入门
- 鼠标移入移出时定时器加速的原因_购买游戏鼠标的几点关键 你必须知道
- MYSQL 自定义函数,查询节点所有父节点、查询节点所有子节点