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天的时间销售,一天也只能销售一件商品.问最大获利. 考虑将出售每个物品 ...
随机推荐
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 网格系统实例:嵌套列
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 手机wifi的mac地址是什么??
简单来说,每个能够接入网络的设备,无论是平板.手机.电脑.电视都有一个专门的序号,这个序号就被称为MAC,正常来说可以看做是这款设备的唯一标识,手机里的MAC其实是特指Wi-Fi无线网卡的MAC地址. ...
- Ubuntu 解决TXT文本乱码问题
只要依次在终端输入这两行指令即可: gsettings set org.gnome.gedit.preferences.encodings auto-detected "['GB18030' ...
- uniGUI之学习方法(18)
官方例子D:\Program Files\FMSoft\Framework\uniGUI\Demos\Desktop 在Design里Main上右键,View as Form看到变化的属性. 看出变化 ...
- Swift-如何快速学习Swift
关于本文: 1.说明本文写作的目的 2.整理了Swift的基本语法树 3.看图作文 一.写作目的 昨天看了一个知识专栏,作者讲述的是“如何研究性的学习”.整个课程1个小时9分钟,花了我19块人民币.其 ...
- 网络编程之TCP三次握手,四次断开
目录 TCP三次握手 1:上图的名词解释 2:TCP三次握手过程 3:为什么不能改成两次握手? TCP三次握手 1:上图的名词解释 SYN:同步序号.它表示建立连接.TCP规定SYN=1时不能携带数据 ...
- PaperReading20200221
CanChen ggchen@mail.ustc.edu.cn Busy... Human-level concept learning through probabilistic program i ...
- 初学微信小程序——配置问题(2)
六.生命周期函数: 在微信公众平台指南中搜索生命周期,找到页面生命周期 比如,我打开cate.js并编写,代码如下: ** * 生命周期函数--监听页面加载 */ onLoad: function ...
- XML中报错
错误描述如下: Multiple annotations found at this line: - cvc-complex-type.2.4.a: Invalid content was found ...
- matlab练习程序(概率路线图PRM)
PRM概率路线图全称 Probabilistic Roadmap,是一种路径规划算法,利用随机撒点的方式将空间抽样并将问题转为图搜索,利用A*或Dijkstra算法找到起始结束节点的最短路径. 可以想 ...