3709: [PA2014]Bohater
3709: [PA2014]Bohater
或者:Bohater

题解
好狠啊这个题 z 要开 long long ,可能算掉血回血的时候会爆 long long 吧
首先把能回血的怪打死(不然你后面血不够咋办)
打回血怪的顺序按照消耗血量升序排列
然后再考虑杀掉血怪

当我们杀完所有怪物,最后的体力值是确定的
然后我们倒着看,杀掉血怪的时候,我们当做将血瓶吐出来还给掉血怪,然后掉血怪把消耗的血再还给你,然后推回去,看看能不能到达杀回血怪最后的血量巅峰,所以倒着看,处理就和杀回血怪差不多了,倒着看是按照回血量升序,正着看就是降序了

把问题分成两部分:
1.处理回血怪,到达血量巅峰,按照耗血量升序排序
2.处理掉血怪,能不能从血量巅峰不降到0及以下(或者是看看能不能回到血量巅峰),按照回血量从大到小排序(正着看)
好狠啊这个题 z 要开 long long ,可能算掉血回血的时候会爆 long long 吧
代码
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue> using namespace std; inline int read()
{
int ans=;
char last=' ',ch=getchar();
while(ch<''||ch>'') last=ch,ch=getchar();
while(ch>=''&&ch<='') ans=ans*+ch-'',ch=getchar();
if(last=='-') ans=-ans;
return ans;
} int n,up_num=,down_num=;
long long z;
struct node
{
int d,a,num;
}up[],down[]; bool cmp1(node x,node y)
{
return x.d <y.d ;
} bool cmp2(node x,node y)
{
return x.a >y.a ;
} int main()
{
n=read();z=read();
int x,y;
for(int i=;i<=n;i++)
{
x=read();y=read();
if(x<=y) up[++up_num].num =i,up[up_num].d =x,up[up_num].a =y;
else down[++down_num].num =i,down[down_num].d =x,down[down_num].a =y;
}
sort(up+,up+up_num+,cmp1);
sort(down+,down+down_num+,cmp2);
for(int i=;i<=up_num;i++)
{
if(up[i].d >=z){printf("NIE\n");return ;}
else z=z-up[i].d +up[i].a ;
}
for(int i=;i<=down_num;i++)
{
if(down[i].d >=z){printf("NIE\n");return ;}
else z=z-down[i].d +down[i].a ;
}
printf("TAK\n");
for(int i=;i<=up_num;i++)
printf("%d ",up[i].num );
for(int i=;i<=down_num;i++)
printf("%d ",down[i].num );
return ;
}
Z要开 long long
3709: [PA2014]Bohater的更多相关文章
- BZOJ 3709: [PA2014]Bohater
3709: [PA2014]Bohater Time Limit: 5 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 1050 Solved: ...
- 【贪心】bzoj 3709:[PA2014]Bohater
3709: [PA2014]Bohater Time Limit: 5 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 653 Solved: ...
- 【BZOJ】3709: [PA2014]Bohater(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=3709 很水的题...但是由于脑洞小..漏想了一种情况.. 首先显然能补血的先杀.. 然后杀完后从补血 ...
- BZOJ 3709 [PA2014]Bohater:贪心【反过来考虑】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3709 题意: 在一款电脑游戏中,你需要打败n只怪物(从1到n编号). 为了打败第i只怪物, ...
- bzoj 3709: [PA2014]Bohater 贪心
题目: 在一款电脑游戏中,你需要打败\(n\)只怪物(从\(1\)到\(n\)编号).为了打败第\(i\)只怪物,你需要消耗\(d_i\)点生命值,但怪物死后会掉落血药,使你恢复\(a_i\)点生命值 ...
- bzoj 3709: [PA2014]Bohater【贪心】
先打能回血的,按消耗从小到大打: 然后按回血量降序打剩下的(把消耗和回血反着看就是上一种怪,打法一样): 中间体力小于0就输出无解 #include<iostream> #include& ...
- 【BZOJ 3709: [PA2014]Bohater】
首先,这是我n久之前培训的时候老师讲的题目了,今天突然看到,那就讲讲吧. 首先,我们考虑怎么打怪... 显然,我们需要保证这个怪要尽可能的打死(就是尽量不被干死),并且保证尽可能的净获得血量大的在前面 ...
- BZOJ3709: [PA2014]Bohater
3709: [PA2014]Bohater Time Limit: 5 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 339 Solved: ...
- [PA2014]Bohater
[PA2014]Bohater 题目大意: 有\(n(n\le10^5)\)只怪物,你的血量为\(z\).要打败第\(i\)只怪物时,你需要先消耗\(d_i\)点生命值,再恢复\(a_i\)点生命值. ...
随机推荐
- centos7重启网卡报Job for network.service failed because...错误
解决: [root@mina0 hadoop]# systemctl stop NetworkManager[root@mina0 hadoop]# systemctl disable Network ...
- nohup命令(Linux终端启动后台运行程序)
1. nohup指令基本概念: nohup: 不挂断的运行,并没有后台运行功能,用nohup运行命令可以使命令永久执行下去,和用户终端没有关系,断开SSH不影响运行,&是后台运行. nohup ...
- 【安徽集训】fiend
考试的时候只会 \(O(Tn^3)\) 的做法,其它题还都不会,想到一整场就打这么点是人都能写的暴力没啥意思,就懒得写了.. Description 双人博弈.每一轮 A 和 B 同时选择一个 \(1 ...
- UVA 1482 SG打表
打出SG表来可以很容易的发现i为偶数时 SG[i]=i/2 i为奇数时 SG[i]=SG[i/2] #include<bits/stdc++.h> typedef long long ll ...
- unique() sstream
sstream ss()自动去除空格 例: string a="1 2 3 4 5; getline(cin,a); sstream ss(a); while(ss>>b) { ...
- R树-javascript代码实现过程分析(插入操作)
R Tree 第一步,创建R树类. 构建一个RTree生成器.用以创建tree对象. 例子:var tree = new RTree(12) var RTree = function(width){ ...
- c# 获取api 数据
private string GetDataFromServerApi(string url, string body) { string str = ""; try { Http ...
- Javascript设计模式之发布-订阅模式
简介 发布-订阅模式又叫做观察者模式,他定义了一种一对多的依赖关系,即当一个对象的状态发生改变的时候,所有依赖他的对象都会得到通知. 回忆曾经 作为一名前端开发人员,给DOM节点绑定事件可是再频繁不过 ...
- 使用Apache Curator管理ZooKeeper(转)
Apache ZooKeeper是为了帮助解决复杂问题的软件工具,它可以帮助用户从复杂的实现中解救出来. 然而,ZooKeeper只暴露了原语,这取决于用户如何使用这些原语来解决应用程序中的协调问题. ...
- 【leetcode】1276. Number of Burgers with No Waste of Ingredients
题目如下: Given two integers tomatoSlices and cheeseSlices. The ingredients of different burgers are as ...