Day5 - H - 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
const int maxm = ;
struct Prod {
int p, d;
bool operator<(const Prod &a) const {
return p > a.p ||(p == a.p && d > a.d);
}
}Prods[maxm];
int fa[maxm];
void init() {
memset(fa, -, sizeof(fa));
}
int Find(int x) {
if(fa[x] == -)
return x;
return fa[x] = Find(fa[x]);
}
int main() {
int N, t1, t2;
while(scanf("%d", &N) != EOF) {
init();
for(int i = ; i < N; ++i) {
scanf("%d%d", &t1, &t2);
Prods[i] = {t1, t2};
}
sort(Prods, Prods+N);
int ans = ;
for(int i = ; i < N; ++i) {
int x = Find(Prods[i].d);
if(x > ) {
ans += Prods[i].p;
fa[x] = x - ;
}
}
printf("%d\n", ans);
}
return ;
}
Day5 - H - Supermarket POJ - 1456的更多相关文章
- (并查集 贪心思想)Supermarket -- POJ --1456
链接: http://poj.org/problem?id=1456 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...
- 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
[题目链接] http://poj.org/problem?id=1456 [算法] 贪心 + 堆 [代码] #include <algorithm> #include <bitse ...
- poj 1456 Supermarket - 并查集 - 贪心
题目传送门 传送点I 传送点II 题目大意 有$n$个商品可以销售.每个商品销售会获得一个利润,但也有一个时间限制.每个商品需要1天的时间销售,一天也只能销售一件商品.问最大获利. 考虑将出售每个物品 ...
随机推荐
- Python 爬取 热词并进行分类数据分析-[热词关系图+报告生成]
日期:2020.02.05 博客期:144 星期三 [本博客的代码如若要使用,请在下方评论区留言,之后再用(就是跟我说一声)] 所有相关跳转: a.[简单准备] b.[云图制作+数据导入] c.[拓扑 ...
- ES的基本概念
elasticsearch 的索引与文档是开发关注的视角:节点.集群.分片是运维关注的视角 elasticearch 文档的介绍 - elasticearch 是面向文档的,文档是所有可搜索数据的最小 ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 排版:使段落突出显示
<!DOCTYPE html> <html> <head> <title>菜鸟教程(runoob.com)</title> <meta ...
- 孤荷凌寒自学python第103天认识区块链017
[主要内容] 今天继续分析从github上获取的开源代码怎么实现简单区块链的入门知识,共用时间25分钟. (此外整理作笔记花费了约34分钟) 详细学习过程见文末学习过程屏幕录像. 今天所作的工作是进一 ...
- EOS主网搭建教程--&&--搭建节点--&&--搭建mongodb数据库
EOS主网搭建教程: 1.git clone https://github.com/EOS-Mainnet/eos.git --recursive 2.cd eos 3.git tag (查看有哪些分 ...
- Kafka 启动报错java.io.IOException: Can't resolve address.
阿里云上 部署Kafka 启动报错java.io.IOException: Can't resolve address. 本地调试的,报错 需要在本地添加阿里云主机的 host 映射 linux ...
- java#临时文件目录
String tmpDir=System.getProperty("java.io.tmpdir");
- web前端面试第一次[定时器]
BOM中定时器--计时器 定时器参数两个:(函数,时间(单位ms(1000ms=1s))) 时间设置1s,每过1s执行一次函数 //设置定时器 setInterval(funtion(){ alert ...
- Java最新面试题
本人免费整理了Java高级资料,涵盖了Java.Redis.MongoDB.MySQL.Zookeeper.Spring Cloud.Dubbo高并发分布式等教程,一共30G,需要自己领取.传送门:h ...
- 无线冲方案 WPC Qi v1.2.4 update
参考: 1. Qi标准v1.2.4最新版 2. Qi Baseline Power Profile (BPP) and Extended Power Profile (EPP) Wireless Ch ...