当前位置:网站首页>(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;
}
边栏推荐
- BAIC bluevale: performance under pressure, extremely difficult period
- 网站源码整站下载 网站模板源代码下载
- Suggest collecting | what to do when encountering slow SQL on opengauss?
- Personal mall two open Xiaoyao B2C mall system source code - Commercial Version / group shopping discount seckill source code
- Is it safe to open a stock account online in 2022? Is there any danger?
- Exposure:A White-Box Photo Post-Processing Framework阅读札记
- 内存泄漏定位工具之 valgrind 使用
- MIT最新论文《对可解释特征的需求:动机和分类》:在机器学习模型的组成元素中建立可解释性
- 全局过滤器(处理时间格式)
- Ask everyone in the group about the fact that the logminer scheme of flick Oracle CDC has been used to run stably in production
猜你喜欢
MIT最新论文《对可解释特征的需求:动机和分类》:在机器学习模型的组成元素中建立可解释性
华为HMS Core携手超图为三维GIS注入新动能
12款大家都在用的产品管理平台
Google's new paper Minerva: solving quantitative reasoning problems with language models
Matplotlib data visualization Foundation
2022年6月编程语言排行,第一名居然是它?!
12 plateformes de gestion de produits utilisées par tout le monde
Ten years of sharpening a sword: unveiling the secrets of ant group's observability platform antmonitor
Uncover the secrets of new products! Yadi Guanneng 3 multi product matrix to meet the travel needs of global users
[.net6] use ml.net+onnx pre training model to liven the classic "Huaqiang buys melons" in station B
随机推荐
爬虫(2) - Requests(1) | Requests模块的深度解析
CANN算子:利用迭代器高效实现Tensor数据切割分块处理
node版本管理器nvm安装及切换
Half of 2022 has passed, isn't it sudden?
力扣(LeetCode)181. 超过经理收入的员工(2022.06.29)
Give up high paying jobs in Shenzhen and go back home
移动硬盘驱动器读到,但不显示盘符
想请教一下,我在广州,到哪里开户比较好?现在网上开户安全么?
金融壹账通拟7月4日香港上市:2年亏近30亿 市值蒸发超90%
关于Keil编译程序出现“File has been changed outside the editor,reload?”的解决方法
华为HMS Core携手超图为三维GIS注入新动能
商城小程序源码开源版-可二开
毕业季·进击的技术er
Infinite innovation in cloud "vision" | the 2022 Alibaba cloud live summit was officially launched
云上“视界” 创新无限 | 2022阿里云直播峰会正式上线
数据库实验报告(一)
Yoda unified data application -- Exploration and practice of fusion computing in ant risk scenarios
Matplotlib数据可视化基础
CVPR 2022 | Virtual Correspondence: Humans as a Cue for Extreme-View Geometry
Leetcode 181 Employees exceeding the manager's income (June 29, 2022)