当前位置:网站首页>(POJ - 1456) supermarket
(POJ - 1456) supermarket
2022-07-01 11:05:00 【AC__ dream】
Topic link :1456 -- Supermarket
The original meaning of the topic is difficult to understand , Below I give a simplified version of the understanding : There is... In the supermarket n A commodity . The first i An item must be within the shelf life ( The first di Days and before ) Sell out , If sold, the supermarket can get pi The profits of the , But you can only sell one item per day , Now you want to maximize the profits of the supermarket , What's the biggest profit , Multiple sets of data
analysis : Greedy thoughts , That is, we first sort the goods according to the profit , It also takes a day , If you can sell the goods with high profits, sell the goods with high profits first , However, under current conditions, we can sell as late as we can ( In order to provide more time for some goods with low profit but short shelf life ), Obviously, this is the right greedy strategy , But how do we achieve it , It is impossible for us to search for any product from its expiration date , If you find a day to sell current goods, sell , Otherwise, don't sell , This complexity is a little high , We can use the union search set to realize this process fu[i] For from i Start looking forward to the spare time you can find , The initial setting is i, Every time we use this spare time, we order fu[fu[i]]=fu[i]-1,( if fu[i]<1 Then the commodity cannot be sold ) Because there is path compression in the process of joint search , So it will greatly reduce our query time
Here is the code :
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
using namespace std;
const int N=10003;
int fu[N];
struct node{
int d,p;
}p[N];
bool cmp(node a,node b)
{
return a.p>b.p;
}
int find(int x)
{
if(x==fu[x]) return x;
return fu[x]=find(fu[x]);
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=1;i<=10000;i++)
fu[i]=i;
for(int i=1;i<=n;i++)
scanf("%d%d",&p[i].p,&p[i].d);
sort(p+1,p+n+1,cmp);
long long ans=0;
for(int i=1;i<=n;i++)
{
int f=find(p[i].d);
if(f>=1)
{
fu[f]=f-1;
ans+=p[i].p;
}
}
printf("%lld\n",ans);
}
return 0;
}
边栏推荐
- Matplotlib数据可视化基础
- 关于Keil编译程序出现“File has been changed outside the editor,reload?”的解决方法
- The first anniversary of the data security law, which four major changes are coming?
- Combination of Oracle and JSON
- CVPR 2022 | 基于密度与深度分解的自增强非成对图像去雾
- Huawei Equipment configure les services de base du réseau WLAN à grande échelle
- Database experiment report (II)
- 华泰证券网上开户安全吗?
- [.net6] use ml.net+onnx pre training model to liven the classic "Huaqiang buys melons" in station B
- Ten years of sharpening a sword: unveiling the secrets of ant group's observability platform antmonitor
猜你喜欢
LeetCode. 515. Find the maximum value in each tree row___ BFS + DFS + BFS by layer
《数据安全法》出台一周年,看哪四大变化来袭?
全局过滤器(处理时间格式)
Addition, deletion, modification and query of database
Brief analysis of edgedb architecture
金融壹账通拟7月4日香港上市:2年亏近30亿 市值蒸发超90%
Matplotlib data visualization Foundation
价值1000毕业设计校园信息发布平台网站源码
NC | 肠道细胞和乳酸菌共同作用来防止念珠菌感染
[.net6] use ml.net+onnx pre training model to liven the classic "Huaqiang buys melons" in station B
随机推荐
Give up high paying jobs in Shenzhen and go back home
[MPC] ① quadratic programming problem matlab solver quadprog
“目标检测”+“视觉理解”实现对输入图像的理解及翻译(附源代码)
MIT最新论文《对可解释特征的需求:动机和分类》:在机器学习模型的组成元素中建立可解释性
What are the advantages and disadvantages of PHP
2022年6月编程语言排行,第一名居然是它?!
Network security learning notes 01 network security foundation
Infinite innovation in cloud "vision" | the 2022 Alibaba cloud live summit was officially launched
Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS
CVPR 2022 | self enhanced unpaired image defogging based on density and depth decomposition
【MAUI】为 Label、Image 等控件添加点击事件
想请教一下,我在广州,到哪里开户比较好?现在网上开户安全么?
Global filter (processing time format)
China's cellular Internet of things users have reached 1.59 billion, and are expected to surpass mobile phone users within this year
[.net6] use ml.net+onnx pre training model to liven the classic "Huaqiang buys melons" in station B
Is it safe to open a stock account online in 2022? Is there any danger?
想开个户,在网上开华泰证券的户安全吗?
CVPR 2022 | Virtual Correspondence: Humans as a Cue for Extreme-View Geometry
Combinaison Oracle et json
Technology sharing | introduction to linkis parameters