Supermarket POJ - 1456(贪心)】的更多相关文章

#include<iostream> #include<algorithm> using namespace std; const int N=1e5; struct edge{ int w; int deadline; }e[N]; bool cmp(edge a,edge b) { return a.w>b.w; } int f[N]; int find(int x) { if(f[x]!=x) f[x]=find(f[x]); return f[x]; } int ma…
链接: http://poj.org/problem?id=1456 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#problem/G 代码: #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #include<cstdlib> us…
题目大意:n个物品,每个物品有一定的保质期d和一定的利润p,一天只能出售一个物品,问最大利润是多少? 题解:这是一个贪心的题目,有两种做法. 1 首先排序,从大到小排,然后每个物品,按保质期从后往前找,找到第一个没被占用的日期,然后出售. code: #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> using namespace std; typedef lo…
有n件商品,每件商品有它的利润和售出的最后期限,问能够得到的最大利润是多少 这道题和 HDU 1789 Doing Homework again 几乎一模一样,只不过这个是求最的扣分,本题是求最大利润 朴素的做法是: 按照每件商品的利润从大到小排序,有一个busy数组记录那天是否有东西卖出.对于每件商品,从它的截止日期开始遍历,如果那天有东西卖就看看前一天是否有卖东西,直到有一天没有东西卖或者前面的天数都有卖的. //#define LOCAL #include <iostream> #inc…
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…
做法一:直接贪心,按照利润排序,然后直接尽量给每个活动安排到最晚的时间即可.时间复杂度O(n * d)当d都为10000时,很容易超时.由于这题数据比较水,所有贪心未超时. AC代码 #include <cstdio> #include <cmath> #include <cctype> #include <algorithm> #include <cstring> #include <utility> #include <st…
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…
题意:有n个商品,每个商品如果能在截止日期之前售出就会获得相应利益,求能获得的最大利益 一开始对每个时间进行贪心,后来发现后面的商品可以放到之前来卖,然后就wa了 这里就直接对价格排序,把物品尽量放到最后卖,如果在这个时间有物品卖了,就往前卖,直到前面所有的时间都满了 #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath>…
题意:给定n个商品的deadline和profit,求每天卖一件的情况下的最大获利 显然是一道贪心 按deadline从小到大排序好,动态维护小根(profit)堆的大小<=当前deadline的天数,往里面符合条件的尽可能塞更优解 注意有n为0的情况 还有脑抽导致判断条件缺斤少两,下次不要这样了 /*H E A D*/ struct Node{ ll p,d,id; }a[maxn]; bool cmp(Node a,Node b){ if(a.d!=b.d)return a.d<b.d;…
F - Supermarket Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1456 Appoint description:  System Crawler  (2015-11-30) Description A supermarket has a set Prod of products on sale. It earns a p…