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天的时间销售,一天也只能销售一件商品.问最大获利. 考虑将出售每个物品 ...
随机推荐
- iOS中统计平台的使用
iOS腾讯Bugly使用 https://www.jianshu.com/p/f672e0d202ef iOS 百度统计的使用技巧 https://blog.csdn.net/yy1992320/a ...
- vue注册全局过滤器
1.src目录下创建filter文件 /** * 男女 * @param val * @returns {string} */ const status = val => { let name ...
- SQL查询效率注意事项 2011.12.27
一.查询条件精确,针对有参数传入情况 二.SQL逻辑执行顺序 FROM-->JOIN-->WHERE-->GROUP-->HAVING-->DISTINCT-->O ...
- static的特性
1,static方法就是没有this的方法.在static方法内部不能调用非静态方法,反过来是可以的.而且可以在没有创建任何对象的前提下,仅仅通过类本身来调用static方法.这实际上正是static ...
- 学习笔记(15)- 保险行业的问答语料 insuranceqa_data
数据概览 ''' pool data are translated Chinese data with Google API from original English data ''' POOL_T ...
- Android SDCard文件、目录操作【转】
一.权限问题 参考:http://www.cnblogs.com/sky-zhang/p/3403393.html Android框架是基于Linux内核构建,所以Android安全系统也是基于Lin ...
- JS事件委托或者事件代理原理以及实现
事件委托(事件代理)原理:简单的说就是将事件交由别人来执行,就是将子元素的事件通过冒泡的形式交由父元素来执行. 为什么要用时间委托? 在JavaScript中,添加到页面上的事件处理程序数量将直接关系 ...
- 解题报告:luogu P1433 吃奶酪
题目链接:P1433 吃奶酪 我感觉可以改成:[模板]TSP问题(商旅问题) 了. 爆搜\(T\)一个点,考虑状压\(dp\)(还是爆搜). 我们用\(dp[i][j]\)表示现在是\(i\)状态,站 ...
- webpack的配置文件[webpack.config.js]
如果项目里没有webpack.config.js这个文件,webpack会使用它本身内置在源码里的配置项. webpack.config.js这个配置名称可以通过指令修改 npx webpack -- ...
- ABC154F - Many Many Paths
梦回高中,定义的f(i,j)为从(0,0)到(i,j)一共有多少条路可以选择,易知我们要做i+j次选择,其中有i次是选择x轴,剩下的是y轴,所以f(i,j)=C(i+j,i)=C(i+j,j),给你一 ...