当前位置:网站首页>(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;
}边栏推荐
- 英特爾實驗室公布集成光子學研究新進展
- [.net6] use ml.net+onnx pre training model to liven the classic "Huaqiang buys melons" in station B
- 华泰证券网上开户安全吗?
- kubernetes之ingress探索实践
- China's cellular Internet of things users have reached 1.59 billion, and are expected to surpass mobile phone users within this year
- flutter path_provider: ^2.0.10可以获取临时目录
- Sqlachemy common operations
- Want to open an account, is it safe to open an account of Huatai Securities online?
- Intel Labs announces new progress in integrated photonics research
- 转义字符串
猜你喜欢

PHP有哪些优势和劣势

LeetCode.515. 在每个树行中找最大值___逐一BFS+DFS+按层BFS

CVPR 2022 | 基于密度与深度分解的自增强非成对图像去雾

Brief analysis of edgedb architecture

y48.第三章 Kubernetes从入门到精通 -- Pod的状态和探针(二一)

NC | intestinal cells and lactic acid bacteria work together to prevent Candida infection

Detailed explanation of linear regression in machine learning

全局过滤器(处理时间格式)

Global filter (processing time format)

Combination of Oracle and JSON
随机推荐
华为设备配置大型网络WLAN基本业务
escape sequence
Combinaison Oracle et json
Ask everyone in the group about the fact that the logminer scheme of flick Oracle CDC has been used to run stably in production
Node version manager NVM installation and switching
bash: ln: command not found
Harbor webhook从原理到构建
LeetCode. 515. Find the maximum value in each tree row___ BFS + DFS + BFS by layer
dotnet 控制台 使用 Microsoft.Maui.Graphics 配合 Skia 进行绘图入门
[matytype] insert MathType inter line and intra line formulas in CSDN blog
Valgrind usage of memory leak locating tool
Rising stars in Plant Sciences (rsps2022) final Science Lecture (6.30 pm)
Want to open an account, is it safe to open an account of Huatai Securities online?
CVPR 2022 | 基于密度与深度分解的自增强非成对图像去雾
[.NET6]使用ML.NET+ONNX预训练模型整活B站经典《华强买瓜》
Guys, how to export iceberg data to MySQL? What tools are there? Neither sqoop nor dataX
网站源码整站下载 网站模板源代码下载
Paxos 入门
Mall applet source code open source version - two open
LeetCode.每日一题 剑指 Offer II 091. 粉刷房子 (DP问题)