CodeForces 976E(贪心)

题目大意是给定N个随从的生命与攻击,a张牌能够让生命值翻倍,b张牌能够让生命值与攻击力交换,问最终的场攻和为多少?
首先我们要按照hp-dmg降序排列,然后要知道如果要让场攻最大,那么心火一定是把所有的加在一个随从上,但是这个随从未知。我们算出前k个交换的场攻变化然后枚举心火给谁即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,k,sum,ans,jk;
struct node
{
ll hp,dmg,m;
}a[200005];
bool cmp(node a,node b)
{
return a.m>b.m;
}
int main()
{
ios::sync_with_stdio(0);
cin>>n>>m>>k;
k=min(k,n);
for(int i=1;i<=n;i++)
{
cin>>a[i].hp>>a[i].dmg;
a[i].m=max(0LL,a[i].hp-a[i].dmg);
sum+=a[i].dmg;
}
if(!k) cout<<sum;
else
{
sort(a+1,a+1+n,cmp);
for(int i=1;i<=k;i++) jk+=a[i].m;
for(int i=1;i<=n;i++) ans=max(ans,(jk-a[i<=k?i:k].m+(a[i].hp<<m)-a[i].dmg));
cout<<sum+ans;
}
}
就算是一分钱,也是对作者极大的支持
------ 本文结束 ------

版权声明

Baccano by baccano is licensed under a Creative Commons BY-NC-ND 4.0 International License.
baccano创作并维护的Baccano博客采用创作共用保留署名-非商业-禁止演绎4.0国际许可证
本文首发于baccano 博客( http://baccano.fun ),版权所有,侵权必究。

小游戏

---小游戏:要不要来选择一下自己可能的老婆?---

简易发声器

---简易的七键钢琴插件---

可以使用鼠标点击琴键也可以使用主键盘1-7或者小键盘的1-7来操作

那么现在开始吧

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
0%