题目链接

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. records_in_range start_key, end_key

    select * from federatedTest where name='aaa';(gdb) p *start_key$2 = {key = 0x7f64f4103be8 "&quo ...

  2. redmine本地安装部署

    1.railsinstaller-3.2.0.exe 下载地址 http://railsinstaller.org/en 安装railsinstaller  一直点next就可以了,安装完成之后C盘会 ...

  3. Selenium 入门到精通系列:六

    Selenium 入门到精通系列 PS:Checkbox方法 例子 HTML: <html> <head> <title>测试页面</title> &l ...

  4. JavaScript 之 对象/JSON/数组

    对象 简单说,所谓对象,就是一种无序的数据集合,由若干个“键值对”(key-value)构成. var obj = { p: 'Hello World' }; 上面代码中,大括号就定义了一个对象,它被 ...

  5. 259 [LeetCode] 3Sum Smaller 三数之和较小值

    题目: Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 ...

  6. [原创]Docker学习记录: Shipyard+Swarm+Consul+Service Discover 搭建教程

    网上乱七八糟的资料实在是太多了, 乱, 特别乱, 而看书呢, 我读了2本书, 一本叫做<>, 另一本叫做<< Docker进阶与实战>> 在 服务发现这块讲的又不清 ...

  7. POJ 1655 Balancing Act(求树的重心)

    Description Consider a tree T with N (1 <= N <= 20,000) nodes numbered 1...N. Deleting any nod ...

  8. 适合初学者的嵌入式Linux计划

    俗话说万事开头难,刚开始的时候,你是否根本就不知如何开始,上网查资料被一堆堆新名词搞的找不到北,去图书馆看书也是找不到方向?又是arm,又是linux,又是uboot头都大了,不知道自己究竟从哪里开始 ...

  9. 《剑指Offer》题二十一~题三十

    二十一.调整数组顺序使奇数位于偶数前面 题目:输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有奇数位于数组的前半部分,所有偶数位于数组的后半部分. 测试用例: 功能测试:输入数组中的奇 ...

  10. 一步步学敏捷开发:1、敏捷开发及Scrum介绍

    敏捷开发之 历史背景 20世纪60年代:软件作坊,软件规模小,以作坊式开发为主:70年代:软件危机,硬件飞速发展,软件规模和复杂度激增,引发软件危机:80年代:软件过程控制,引入成熟生产制造管理方法, ...