CF613B Skills

洛谷评测传送门

题目描述

Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly nn skills. Each skill is represented by a non-negative integer a_{i}a**i — the current skill level. All skills have the same maximum level AA .

Along with the skills, global ranking of all players was added. Players are ranked according to the so-called Force. The Force of a player is the sum of the following values:

  • The number of skills that a character has perfected (i.e., such that a_{i}=Aa**i=A ), multiplied by coefficient c_{f}c**f .
  • The minimum skill level among all skills ( min\ a_{i}min a**i ), multiplied by coefficient c_{m}c**m .

Now Lesha has mm hacknetian currency units, which he is willing to spend. Each currency unit can increase the current level of any skill by 11 (if it's not equal to AA yet). Help him spend his money in order to achieve the maximum possible value of the Force.

输入格式

The first line of the input contains five space-separated integers nn , AA , c_{f}c**f , c_{m}c**m and mm ( 1<=n<=1000001<=n<=100000 , 1<=A<=10^{9}1<=A<=109 , 0<=c_{f},c_{m}<=10000<=c**f,c**m<=1000 , 0<=m<=10^{15}0<=m<=1015 ).

The second line contains exactly nn integers a_{i}a**i ( 0<=a_{i}<=A0<=a**i<=A ), separated by spaces, — the current levels of skills.

输出格式

On the first line print the maximum value of the Force that the character can achieve using no more than mm currency units.

On the second line print nn integers a'{i}a**i′ ( a{i}<=a'_{i}<=Aa**i<=a**i′<=A ), skill levels which one must achieve in order to reach the specified value of the Force, while using no more than mm currency units. Numbers should be separated by spaces.

输入输出样例

输入 #1复制

输出 #1复制

输入 #2复制

输出 #2复制

说明/提示

In the first test the optimal strategy is to increase the second skill to its maximum, and increase the two others by 1.

In the second test one should increase all skills to maximum.

题解:

2019.11.5模拟赛T2 15分场

题意:

学技能,一共有\(n\)个技能,每个技能的初始等级是\(a[i]\),满级是\(A\)级,你一共可以为你的技能提升\(m\)级,提升完毕之后的战力为:

\[force=x\times c_m+y\times c_f
\]

(\(x\)为提升完毕之后这些技能中最小的等级,\(y\)为满级技能数量)

现在问一共能获得的最大战力是多少。

解析:

一开始看到这道题觉得是贪心。怎么想都没想到贪心策略。以为是自己太笨了(事实上的确是)

后来搞了一个明知必假的贪心交了上去,骗到了15分。感谢出题人@littleseven

因为没什么意义,我就不放最开始的代码了。

正解:二分+贪心枚举

让我们分析一下:

这个战力只和两个事情有关:满级技能有多少个,级别最低的技能级别有多低。

那么对于我们手中的\(m\)个技能点,我们可以选择先给一些技能加满,也可以选择尽可能地提升所有技能的最低技能级别。然后我们自然而然地想到,那到底是先给技能点满更优呢?还是先提升技能整体素质更优呢?

然后我们就死在这个思路里了。

为什么不能这么想呢?因为这个思路的两个关键字性质并不一样。什么意思呢?你看,这个战力的计算式,与\(c_f\)有关的是满级技能的数量,而与\(c_m\)有关的则是最低等级,我们要满足其中一个条件,必然要牺牲第二个条件,就导致了没有办法确定到底怎么分配技能点才能得出最优解。

怎么办呢?

都试一下子不就好了?

是的,既然我们的两个条件是“此消彼长”的,那么就“一定一动”,枚举一个条件,然后在这个条件下再枚举第二个条件,持续更新答案即可。

也就是说:先把这个等级从小到大排好序,在技能点够用的情况下,从后向前开始枚举点满的技能个数,然后在剩下的技能中用剩下的技能点尽可能地提升最低等级,得出答案。

一算时间复杂度,是\(O(n^2)\)的,超时了。

于是我们想到了“枚举伴侣”——二分

用二分来优化枚举,二分的就是最低等级,一个个判合不合法,然后更新答案即可。

至于怎么判断这个合不合法,可以跑一个前缀和。至于输出最后的方案,可以在更新答案处做一个标记,然后按这个标记分配技能点即可。

代码:

#include<cstdio>
#include<algorithm>
#define int long long
using namespace std;
const int maxn=1e5+10;
int high,cf,cm,n,m;
int level[maxn],b[maxn],s[maxn],ans,tmp1,tmp2;
bool cmp(int x,int y)
{
return level[x]<level[y];
}
int check(int x,int rr)
{
int l,r,mid;
l=0;r=rr;
while(l<r)
{
mid=(l+r+1)>>1;
if(level[b[mid]]<x)
l=mid;
else
r=mid-1;
}
return l;
}
signed main()
{
scanf("%lld%lld%lld%lld%lld",&n,&high,&cf,&cm,&m);
for(int i=1;i<=n;i++)
{
scanf("%lld",&level[i]);
b[i]=i;
}
sort(b+1,b+1+n,cmp);
for(int i=1;i<=n;i++)
s[i]=s[i-1]+level[b[i]];
m+=s[n];
ans=-1;
int i;
for(i=1;i<=n+1;i++)
{
if(high*(n-i+1)+s[i-1]>m)
continue;
if(i==1)
ans=cf*n+cm*high,tmp1=1;
if(i==1)
break;
int l=level[b[1]],r=high;
while(l<r)
{
int mid=(l+r+1)>>1;
int t=check(mid,i-1);
if(high*(n+1-i)+mid*t+s[i-1]-s[t]<=m)
l=mid;
else
r=mid-1;
}
if(ans<cf*(n+1-i)+l*cm)
ans=cf*(n+1-i)+l*cm,tmp1=i,tmp2=l;
}
printf("%lld\n",ans);
for(i=1;i<tmp1;i++)
if(level[b[i]]<tmp2)
level[b[i]]=tmp2;
for(i=tmp1;i<=n;i++)
level[b[i]]=high;
for(i=1;i<=n;i++)
printf("%lld ",level[i]);
return 0;
}

CF613B Skills的更多相关文章

  1. Skills - CF613B

    Lesha plays the recently published new version of the legendary game hacknet. In this version charac ...

  2. How to Develop blade and soul Skills

    How to Develop Skills Each skill can be improved for variation effects. Some will boost more strengt ...

  3. Top Five Communication Skills for Project Managers

    Research among project managers globally identifies top communication skills for leading teams. Lead ...

  4. codeforces 613B B. Skills(枚举+二分+贪心)

    题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  5. Computer skills one can learn within one day

    Computer related technical skills are usually thought as complicated and difficult to understand. It ...

  6. Advice on improving your programming skills

    Programming is cool. But behind the scenes it's also difficult for many people. Many people are defe ...

  7. Codeforces Round #322 (Div. 2) C. Developing Skills 优先队列

    C. Developing Skills Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...

  8. cf581C Developing Skills

    Petya loves computer games. Finally a game that he's been waiting for so long came out! The main cha ...

  9. What skills are needed for machine learning jobs

    What skills are needed for machine learning jobs?机器学习工作必须技能 原文: http://www.quora.com/Machine-Learnin ...

随机推荐

  1. 安装picard

    1.下载 wget https://github.com/broadinstitute/picard/releases/download/2.21.6/picard.jar alias picard= ...

  2. Python 爬虫介绍,什么是爬虫,如何学习爬虫?

    ​ 作为程序员,相信大家对“爬虫”这个词并不陌生,身边常常会有人提这个词,在不了解它的人眼中,会觉得这个技术很高端很神秘.不用着急,我们的爬虫系列就是带你去揭开它的神秘面纱,探寻它真实的面目. 爬虫是 ...

  3. PHP面试题大全(值得收藏)

    PHP进阶.面试:文档.视频资源点击免费获取 一 .PHP基础部分 1.PHP语言的一大优势是跨平台,什么是跨平台? PHP的运行环境最优搭配为Apache+MySQL+PHP,此运行环境可以在不同操 ...

  4. error while loading shared libraries

    https://stackoverflow.com/questions/480764/linux-error-while-loading-shared-libraries-cannot-open-sh ...

  5. 一文告诉你,Kafka在性能优化方面做了哪些举措!

    很多粉丝私信问我Kafka在性能优化方面做了哪些举措,对于相关问题的答案其实我早就写过了,就是没有系统的整理一篇,最近思考着花点时间来整理一下,下次再有粉丝问我相关的问题我就可以潇洒的甩个链接了.这个 ...

  6. Z从壹开始前后端分离【 .NET Core2.2/3.0 +Vue2.0 】框架之七 || API项目整体搭建 6.2 轻量级ORM

    本文梯子 本文3.0版本文章 前言 零.今天完成的蓝色部分 0.创建实体模型与数据库 1.实体模型 2.创建数据库 一.在 IRepository 层设计接口 二.在 Repository 层实现相应 ...

  7. python爬取 “得到” App 电子书信息

    前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: 静觅 崔庆才 PS:如有需要Python学习资料的小伙伴可以加点击下 ...

  8. js键盘事件以及键盘事件拦截

    一.键盘事件 onkeydown: 按下键盘时触发 onkeypress: 按下有值的键时触发 注意: onkeypress按下 Ctrl.Alt.Shift.Meta 这样无值的键,这个事件不会触发 ...

  9. Java正则表达式详细解析

    元字符 正则表达式使用一些特定的元字符来检索.匹配和替换符合规则的字符串 元字符:普通字符.标准字符.限定字符(量词).定位字符(边界字符) 正则表达式引擎 正则表达式是一个用正则符号写出来的公式 程 ...

  10. paypal开发指南

    一.开发者地址: https://developer.paypal.com 使用在paypal上注册的账号登陆即可, 二.沙箱账号 paypay自动会为你创建两个沙箱账号,一个商家,一个买家.在acc ...