[CF521D]Shop
[CF521D]Shop
题目大意:
你有一个长度为\(k(k\le10^5)\)的数列\(A_{1\sim k}\),有\(n(n\le10^5)\)种操作,操作包含以下\(3\)种:
- 将\(A_x\)变成\(y\);
- 将\(A_x\)加上\(y\);
- 将\(A_x\)乘以\(y\)。
定义这个数列的收益为各项之积,你可以从中选\(m\)个操作(每个操作至多选\(1\)次),使得收益最大,求任一操作的方案。
思路:
贪心,对于只有操作\(3\)的情况,显然从大到小贪心更优。
而操作\(2\)可以转化成操作\(3\),操作\(1\)又可以转化成操作\(2\),因此最后还是可以用同样的方式贪心。
源代码:
#include<queue>
#include<cstdio>
#include<cctype>
#include<vector>
#include<algorithm>
#include<functional>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return x;
}
typedef long long int64;
const int N=1e5+1;
int ans[N];
std::pair<int,int> b[N];
struct Modify {
int a,b,c;
bool operator > (const Modify &rhs) const {
return c>rhs.c;
}
};
Modify q[N];
std::vector<std::pair<int,int> > v[N];
struct Node {
int id;
double c;
bool operator < (const Node &rhs) const {
return c<rhs.c;
}
};
std::priority_queue<Node> h;
inline bool cmp(const int &i,const int &j) {
return q[i].a<q[j].a;
}
int main() {
const int k=getint(),n=getint(),m=getint();
for(register int i=1;i<=k;i++) {
v[i].push_back(std::make_pair(getint(),0));
}
for(register int i=1;i<=n;i++) {
q[i].a=getint();
q[i].b=getint();
q[i].c=getint();
if(q[i].a==1) {
b[q[i].b]=std::max(b[q[i].b],std::make_pair(q[i].c-v[q[i].b][0].first,i));
}
if(q[i].a==3) {
h.push((Node){i,1.*q[i].c});
}
}
for(register int i=1;i<=k;i++) {
if(b[i].first>0) v[i].push_back(b[i]);
}
for(register int i=1;i<=n;i++) {
if(q[i].a==2) {
v[q[i].b].push_back(std::make_pair(q[i].c,i));
}
}
for(register int i=1;i<=k;i++) {
std::sort(v[i].begin()+1,v[i].end(),std::greater<std::pair<int,int> >());
int64 sum=v[i][0].first;
for(register unsigned j=1;j<v[i].size();j++) {
h.push((Node){v[i][j].second,1.*(sum+v[i][j].first)/sum});
sum+=v[i][j].first;
}
}
for(register int i=1;!h.empty()&&i<=m;i++) {
ans[++ans[0]]=h.top().id;
h.pop();
}
if(ans[0]==0) {
puts("0");
return 0;
}
std::sort(&ans[1],&ans[ans[0]]+1,cmp);
for(register int i=0;i<=ans[0];i++) {
printf("%d%c",ans[i]," \n"[!(i%ans[0])]);
}
return 0;
}
[CF521D]Shop的更多相关文章
- CF521D Shop 贪心
题意: \(n\)个数,有\(m\)个操作,形如: 1,将\(x_i\)改成\(val_i\) 2,将\(x_i\)加上\(val_i\) 3,将\(x_i\)乘上\(val_i\) 其中第\ ...
- 「CF521D」 Shop
「CF521D」 Shop 传送门 题目说是有三种操作,首先可以知道赋值操作是可以转化为加法操作的,即 \((1,b) \rightarrow (2,b-a_i)\) 然后加法对于一个数你肯定优先选择 ...
- 「CF521D」Shop
传送门 Luogu 解题思路 当只有第三类操作时,我们显然先进行val较大的操作,这是显然的. 那么就考虑把所有的操作都转变为第三类操作. 第一类操作,显然很容易变为第二类操作:单点维护最大的最终结果 ...
- codeforces 632+ E. Thief in a Shop
E. Thief in a Shop time limit per test 5 seconds memory limit per test 512 megabytes input standard ...
- Codeforces632E Thief in a Shop(NTT + 快速幂)
题目 Source http://codeforces.com/contest/632/problem/E Description A thief made his way to a shop. As ...
- poj1157LITTLE SHOP OF FLOWERS
Description You want to arrange the window of your flower shop in a most pleasant way. You have F bu ...
- Magicodes.Shop——版本历史
Magicodes.Shop为湖南心莱信息科技有限公司(xin-lai.com)Magicodes系列产品之一. 产品中引用的Magicodes系列Nuget包的开源库地址为:https://gith ...
- sgu 104 Little shop of flowers 解题报告及测试数据
104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...
- PHP Yii1.1.13(一):命令行创建应用~shop
第一节 初始目录结构 (1)初识目录结构 在创建应用之前,我们来看一下Yii 1.x版本的目录结构:将yii-1.1.13安装文件解压到网站根目录下,打开framework目录,其目录如下图所示 (2 ...
随机推荐
- SVM较全面介绍,干货!(转载)
很不错的一篇介绍SVM的文章,证明通俗易懂! 转自:https://blog.csdn.net/v_july_v/article/details/7624837 前言 动笔写这个支持向量机(suppo ...
- linux中fork()函数详解【转】
转自:http://blog.csdn.net/jason314/article/details/5640969 一.fork入门知识 一个进程,包括代码.数据和分配给进程的资源.fork()函数通过 ...
- Jenkins与网站代码上线解决方案【转】
转自 Jenkins与网站代码上线解决方案 - 惨绿少年 https://www.nmtui.com/clsn/lx524.html 1.1 前言 Jenkins是一个用Java编写的开源的持续集成工 ...
- windows系统下安装tomcat及配置
1.安装测试 1.安装 推荐使用免安装版的Tomcat(放在没有中文和空格的目录下),前提是已经安装了JDK并配置了环境变量. 2.测试 双击startup.bat,浏览器输入url:localhos ...
- CentOS 6.5 rsync+inotify实现数据实时同步备份
CentOS 6.5 rsync+inotify实现数据实时同步备份 rsync remote sync 远程同步,同步是把数据从缓冲区同步到磁盘上去的.数据在内存缓存区完成之后还没有写入到磁盘 ...
- Python 列表推导、迭代器与生成器
1.列表推导 1 2 3 4 5 6 7 8 9 10 11 numbers = [i for i in range(10) if i % 2 == 0] print(numbers) seq = ...
- 《剑指offer》-判断对称二叉树
题目描述 请实现一个函数,用来判断一颗二叉树是不是对称的.注意,如果一个二叉树同此二叉树的镜像是同样的,定义其为对称的. 思路上还是广度优先搜索(BFS)来做的.BFS是依托于STL的queue作为容 ...
- 开发同学的福利--mysql监控工具sqlprofiler,类似sqlserver的profiler工具
最近无意发现了mysql的客户端监控工具“Nero Profile SQL”,刚开始还不知道怎么使用,经过半小时摸索,现将使用步骤写下来. 背景:开发的时候,如果数据存储层这块使用EF,或者其他orm ...
- 设计原则:开-闭原则(Open-Closed Principle, OCP)
开-闭原则就是软件实体应当对扩展开放,对修改关闭.(Software entities should be open for extension,but closed for modification ...
- c3p0和QueryRunner的结合使用,让开发更加简便
1:DBUtils中的QueryRunner的使用: 1.1:QueryRunner中提供了对SQL语句操作的api: 1.2:主要有三个方法: 1.2.1:query():用于执行select(查询 ...