zoukankan      html  css  js  c++  java
  • BZOJ3709 [PA2014]Bohater 【贪心】

    题目链接

    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;
    }
    
    
  • 相关阅读:
    力扣算法题—070爬楼梯
    力扣算法题—069x的平方根
    力扣算法题—068文本左右对齐
    天梯杯 L2-008. 最长对称子串
    CODE[VS] 1294 全排列
    hdu 1829 A Bug's Life(并查集)
    HDU 1213 How Many Tables
    POJ 1182 食物链(经典并查集) (多组输入有时乱加也会错!)
    天梯杯 L2-010. 排座位
    The Suspects POJ1611
  • 原文地址:https://www.cnblogs.com/Mychael/p/9092290.html
Copyright © 2011-2022 走看看