Supermarket POJ - 1456
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
Output
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
- #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的更多相关文章
- (并查集 贪心思想)Supermarket -- POJ --1456
链接: http://poj.org/problem?id=1456 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...
- 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 ...
- Supermarket POJ - 1456 贪心+并查集
#include<iostream> #include<algorithm> using namespace std; const int N=1e5; struct edge ...
- Supermarket POJ - 1456(贪心)
题目大意:n个物品,每个物品有一定的保质期d和一定的利润p,一天只能出售一个物品,问最大利润是多少? 题解:这是一个贪心的题目,有两种做法. 1 首先排序,从大到小排,然后每个物品,按保质期从后往前找 ...
- POJ 1456 Supermarket 区间问题并查集||贪心
F - Supermarket Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- POJ 1456——Supermarket——————【贪心+并查集优化】
Supermarket Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ 1456 - Supermarket - [贪心+小顶堆]
题目链接:http://poj.org/problem?id=1456 Time Limit: 2000MS Memory Limit: 65536K Description A supermarke ...
- poj 1456 Supermarket - 并查集 - 贪心
题目传送门 传送点I 传送点II 题目大意 有$n$个商品可以销售.每个商品销售会获得一个利润,但也有一个时间限制.每个商品需要1天的时间销售,一天也只能销售一件商品.问最大获利. 考虑将出售每个物品 ...
- POJ 1456 Supermarket(贪心+并查集)
题目链接:http://poj.org/problem?id=1456 题目大意:有n件商品,每件商品都有它的价值和截止售卖日期(超过这个日期就不能再卖了).卖一件商品消耗一个单位时间,售卖顺序是可以 ...
随机推荐
- BZOJ 2724: [Violet 6]蒲公英 [分块 区间众数]
传送门 题面太美不忍不放 分块分块 这种题的一个特点是只有查询,通常需要预处理:加入修改的话需要暴力重构预处理 预处理$f[i][j]$为第i块到第j块的众数,显然$f[i][j]=max{f[i][ ...
- JAVA 二进制基础
主要内容 1.十进制二进制互转 2.二进制的位运算 3.JDK内置的进制转换 4.JAVA中的进制 十进制二进制互转 57 111001 二进制的位运算:优点:特定情况下,计算方便,被支持面广泛. ① ...
- selenium+requests访问微博
import requests from selenium import webdriver from selenium.webdriver.support import expected_condi ...
- Job 失败了怎么办?- 每天5分钟玩转 Docker 容器技术(133)
上一节讨论了 Job 执行成功的情况,如果失败了会怎么样呢? 修改 myjob.yml,故意引入一个错误: 先删除之前的 Job: 如果将 restartPolicy 设置为 OnFailure 会怎 ...
- 反反爬虫 IP代理
0x01 前言 一般而言,抓取稍微正规一点的网站,都会有反爬虫的制约.反爬虫主要有以下几种方式: 通过UA判断.这是最低级的判断,一般反爬虫不会用这个做唯一判断,因为反反爬虫非常容易,直接随机UA即可 ...
- css scale 元素放大缩小效果
<style> .trans-scale { width: 300px; height:300px; margin:100px auto; background:#99F; transit ...
- PHP函数register_shutdown_function的用法
register_shutdown_function这个函数是在PHP程序运行结束之前调用的,用这个函数可以做很多,比如调用运行发生致命错误中止的原因,或者调试程序的执行时间等. PHP终止的情况有哪 ...
- 老男孩Python全栈开发(92天全)视频教程 自学笔记07
day7课程内容: Python的编码解码 二进制 --->ASCII:只能存英文和拉丁字符,一个字符占一个字节,8位 ------->gb2312:只能6700多个中文,1980年 -- ...
- 如何使用 libqr 库生成二维码?
使用 libqr 库只需 4 步即可生成二维码 1.初始化 QRCode 结构体 QRCode *qrInit(int version, int mode, int eclevel, int mask ...
- CodeForces - 727E Games on a CD 字符串Hash
题意:有n个单词,每个单词长度为k,顺时针将它们写成一个圆圈串.现在知道g个长度为k的单词,是否可以从这g个单词中选择n个形成这个圆圈串?如果有多个答案,任意输出一个. 思路 可以发现,如果枚举第一个 ...