题目链接

BZOJ3709

题解

贪心很显然

我们先干掉能回血的怪,当然按照\(d\)升序顺序,因为打得越多血越多,\(d\)大的尽量往后打

然后再干掉会扣血的怪,当然按照\(a\)降序顺序,因为最后受的伤害一定,回的血也一定,先尽量回多的血以尽量承受住当前伤害

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b) make_pair<int,int>(a,b)
#define cls(s) memset(s,0,sizeof(s))
#define cp pair<int,int>
#define LL long long int
using namespace std;
const int maxn = 100005,maxm = 100005,INF = 1000000000;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
struct node{int a,d,id;}a[maxn],b[maxn];
inline bool cmp1(const node& a,const node& b){
return a.d < b.d;
}
inline bool cmp2(const node& a,const node& b){
return a.a > b.a;
}
int n,ai,bi;
LL z;
int main(){
n = read(); z = read();
int x,y;
REP(i,n){
x = read(); y = read();
if (y >= x) a[++ai] = (node){y,x,i};
else b[++bi] = (node){y,x,i};
}
sort(a + 1,a + 1 + ai,cmp1);
for (int i = 1; i <= ai; i++){
if (z <= a[i].d){puts("NIE"); return 0;}
z = z - a[i].d + a[i].a;
}
sort(b + 1,b + 1 + bi,cmp2);
for (int i = 1; i <= bi; i++){
if (z <= b[i].d){puts("NIE"); return 0;}
z = z - b[i].d + b[i].a;
}
puts("TAK");
for (int i = 1; i <= ai; i++)
printf("%d ",a[i].id);
for (int i = 1; i <= bi; i++)
printf("%d ",b[i].id);
return 0;
}

BZOJ3709 [PA2014]Bohater 【贪心】的更多相关文章

  1. bzoj3709: [PA2014]Bohater 贪心

    ~~~题面~~~ 题解: 首先有一个比较明显的策略,肯定先要把能带给自己受益的先选完,然后再以最佳状态去打那些会给自己带来损失的怪. 对于前一部分(可以带来受益的怪),显然我们需要先从代价小的打起,因 ...

  2. [bzoj3709][PA2014]Bohater_贪心

    bzoj-3709 PA-2014 Bohater 题目大意:在一款电脑游戏中,你需要打败n只怪物(从1到n编号).为了打败第i只怪物,你需要消耗d[i]点生命值,但怪物死后会掉落血药,使你恢复a[i ...

  3. 【BZOJ-3709】Bohater 贪心

    3709: [PA2014]Bohater Time Limit: 5 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 835  Solved:  ...

  4. BZOJ3709: [PA2014]Bohater

    3709: [PA2014]Bohater Time Limit: 5 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 339  Solved: ...

  5. bzoj3709: [PA2014]Bohater(贪心)

    贪心... 可以回血的按d[i]升序防止死掉 不能回血的按a[i]降序,因为只考虑d我们要扣除的血量是一定的,为了不死显然回血多的放前面更好 #include<iostream> #inc ...

  6. 【贪心】bzoj3709 [PA2014]Bohater

    把怪分成两类看: 一.回血>损血 则若先杀损血少的再杀损血多的,则为当前这一步提供了更高的可能性.因为血量是单增的,所以尽量用较少的血量去干♂耗血较少的怪物. 二.回血<损血 则若先杀回血 ...

  7. 【BZOJ4619/3709】[Wf2016]Swap Space/[PA2014]Bohater 贪心

    [BZOJ4619][Wf2016]Swap Space Description 你有许多电脑,它们的硬盘用不同的文件系统储存数据.你想要通过格式化来统一文件系统.格式化硬盘可能使它的容量发生变化.为 ...

  8. bzoj 3709: [PA2014]Bohater 贪心

    题目: 在一款电脑游戏中,你需要打败\(n\)只怪物(从\(1\)到\(n\)编号).为了打败第\(i\)只怪物,你需要消耗\(d_i\)点生命值,但怪物死后会掉落血药,使你恢复\(a_i\)点生命值 ...

  9. 【贪心】bzoj 3709:[PA2014]Bohater

    3709: [PA2014]Bohater Time Limit: 5 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 653  Solved:  ...

随机推荐

  1. UpdateLog

    2014-10-20 增加数据适配器,使支持多数据库类型2015-01-08 增加没有主键ID的抽象类,使能自义主键字段实现MODEL 增加虚拟字段转换,将指定函数或语法转换为对象属性,灵活性更大了 ...

  2. 「日常训练」 Genghis Khan the Conqueror(HDU-4126)

    题意 给定\(n\)个点和\(m\)条无向边(\(n\le 3000\)),需要将这\(n\)个点连通.但是有\(Q\)次(\(Q\le 10^4\))等概率的破坏,每次破坏会把\(m\)条边中的某条 ...

  3. Fiddler使用总结(二)

    在上一篇中介绍了Fiddler的基本使用方法.通过上一篇的操作我们可以直接抓取浏览器的数据包.但在APP测试中,我们需要抓取手机APP上的数据包,应该怎么操作呢? Andriod配置方法: .确保手机 ...

  4. idea前端页面不刷新----springboot

    修改这里就好了

  5. * 197. Permutation Index【LintCode by java】

    Description Given a permutation which contains no repeated number, find its index in all the permuta ...

  6. FPGA学习-PS2接口

    选自http://m.elecfans.com/article/774143.html

  7. 一键部署 Docker Datacenter ---简化docker数据中心安装步骤

    DDC 简介 2016年2月下旬,Docker发布了企业级容器管理和服务部署的整体解决方案平台-Docker Datacenter,简称DDC.DDC 有三个组件构成:1. Docker Univer ...

  8. net::ERR_ABORTED ,引入js文件出现报错的解决方法

    在head头里面添加 <mvc:annotation-driven enable-matrix-variables="true"></mvc:annotation ...

  9. Rescue(BFS时间最短 另开数组或优先队列)

    Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M ...

  10. Catch That Cow(BFS广搜)

    Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...