BZOJ3709 [PA2014]Bohater 【贪心】
2024-10-11 01:43:39
题目链接
题解
贪心很显然
我们先干掉能回血的怪,当然按照\(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;
}
最新文章
- spring xmlns 记录
- Java基本概念(1)什么是Java
- php中防止SQL注入的方法
- iOS 架构模式--解密 MVC,MVP,MVVM以及VIPER架构
- 第5.5次Scrum会议
- Python文件操作题
- Continuous Subarray Sum
- bzoj 1036 Tree Count
- Win7下Solr4.10.1和TomCat8的安装
- VS2010中xercesc配置及简单示例
- VC6神迹外挂的DIY
- 使用py2exe发布windows平台Python
- ";每日一道面试题";.net托管堆是否会存在内存泄漏的情况
- mysql 外键和子查询,视图
- F - Tmutarakan Exams URAL - 1091 -莫比乌斯函数-容斥 or DP计数
- 20155326刘美岑2016-2017-2《Java程序设计》第一周学习总结
- [转]如何在本地apache上架设多个站点
- BZOJ 1340: [Baltic2007]Escape逃跑问题
- 【BZOJ】【1006】【HNOI2008】神奇的国度
- (剑指Offer)面试题3:二维数组中的查找