zoukankan      html  css  js  c++  java
  • 【BZOJ】3709: [PA2014]Bohater(贪心)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3709

    很水的题。。。但是由于脑洞小。。漏想了一种情况。。

    首先显然能补血的先杀。。

    然后杀完后从补血越多的杀。。(这点我之前考虑错了QAQ)

    正确性显然。。。。。。。。

    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <string>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <set>
    #include <map>
    using namespace std;
    typedef long long ll;
    #define rep(i, n) for(int i=0; i<(n); ++i)
    #define for1(i,a,n) for(int i=(a);i<=(n);++i)
    #define for2(i,a,n) for(int i=(a);i<(n);++i)
    #define for3(i,a,n) for(int i=(a);i>=(n);--i)
    #define for4(i,a,n) for(int i=(a);i>(n);--i)
    #define CC(i,a) memset(i,a,sizeof(i))
    #define read(a) a=getint()
    #define print(a) printf("%d", a)
    #define dbg(x) cout << (#x) << " = " << (x) << endl
    #define error(x) (!(x)?puts("error"):0)
    #define rdm(x, i) for(int i=ihead[x]; i; i=e[i].next)
    inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
    
    #define spj puts("NIE"); return 0;
    const int N=100005;
    int n, m, ans[N], cnt;
    ll now;
    struct dat { int a, b, id; }x[N];
    bool cmp1(const dat &a, const dat &b) { return a.a<b.a; }
    bool cmp2(const dat &a, const dat &b) { return a.b<b.b; }
    int main() {
    	read(n); read(now);
    	for1(i, 1, n) read(x[i].a), read(x[i].b), x[i].id=i;
    	sort(x+1, x+1+n, cmp1);
    	for1(i, 1, n) if(x[i].a<=x[i].b) { if(now<=x[i].a) { spj } now+=x[i].b-x[i].a, ans[++cnt]=x[i].id; }
    	sort(x+1, x+1+n, cmp2);
    	for3(i, n, 1) if(x[i].a>x[i].b) { if(now<=x[i].a) { spj } now+=x[i].b-x[i].a, ans[++cnt]=x[i].id; }
    	puts("TAK");
    	for1(i, 1, n) printf("%d ", ans[i]);
    	return 0;
    }
    

      


    Description

    在一款电脑游戏中,你需要打败n只怪物(从1到n编号)。为了打败第i只怪物,你需要消耗d[i]点生命值,但怪物死后会掉落血药,使你恢复a[i]点生命值。任何时候你的生命值都不能降到0(或0以下)。请问是否存在一种打怪顺序,使得你可以打完这n只怪物而不死掉

    Input

    第一行两个整数n,z(1<=n,z<=100000),分别表示怪物的数量和你的初始生命值。
    接下来n行,每行两个整数d[i],a[i](0<=d[i],a[i]<=100000)

    Output

    第一行为TAK(是)或NIE(否),表示是否存在这样的顺序。
    如果第一行为TAK,则第二行为空格隔开的1~n的排列,表示合法的顺序。如果答案有很多,你可以输出其中任意一个。

    Sample Input

    3 5
    3 1
    4 8
    8 3

    Sample Output

    TAK
    2 3 1

    HINT

     

    Source

  • 相关阅读:
    冲突域和广播域的区分
    internet 的一词多义
    大神洗礼第四讲——函数相关及编程技巧
    旋转字符串算法由浅入深
    一个交换程序的通用版本
    想起一些事情,都很遥远
    [转载]创业感想
    [转载]javascript小技巧
    [转载]在Asp.Net 2.0中应用DataFormatString
    [转载]C#的String.Format格式化举例
  • 原文地址:https://www.cnblogs.com/iwtwiioi/p/4154436.html
Copyright © 2011-2022 走看看