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

    把怪分成两类看:

    一、回血>损血 则若先杀损血少的再杀损血多的,则为当前这一步提供了更高的可能性。因为血量是单增的,所以尽量用较少的血量去干♂耗血较少的怪物。

    二、回血<损血 则若先杀回血多的再杀回血少的,则为下一步提供了更高的可能性。当前这一步的可能性也没有减少,因为即使回血多的损血很多,但是由于此时血量已经是单减的了,所以若此时无法杀掉损血多的,将来也不能。

    ORZ TimeMachine And ZKY

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<algorithm>
     4 using namespace std;
     5 typedef long long ll;
     6 struct Point{ll x,y;int p;Point(const ll &a,const ll &b,const int &c){x=a;y=b;p=c;}Point(){}};
     7 Point a[100011],b[100011];
     8 int en1,en2,n;
     9 bool cmp1(const Point &a,const Point &b){return a.x<b.x;}
    10 bool cmp2(const Point &a,const Point &b){return a.y>b.y;}
    11 ll hp,x,y;
    12 int main()
    13 {
    14     cin>>n>>hp;
    15     for(int i=1;i<=n;i++)
    16       {
    17           cin>>x>>y;
    18           if(y>x) a[++en1]=Point(x,y,i);
    19           else b[++en2]=Point(x,y,i);
    20       }
    21     sort(a+1,a+en1+1,cmp1);
    22     sort(b+1,b+en2+1,cmp2);
    23     for(int i=1;i<=en1;i++)
    24       {
    25           hp-=a[i].x;
    26           if(hp<=0) {puts("NIE"); return 0;}
    27           hp+=a[i].y;
    28       }
    29     for(int i=1;i<=en2;i++)
    30       {
    31           hp-=b[i].x;
    32           if(hp<=0) {puts("NIE"); return 0;}
    33           hp+=b[i].y;
    34       }
    35     puts("TAK");
    36     for(int i=1;i<=en1;i++) printf("%d ",a[i].p);
    37     for(int i=1;i<=en2;i++) printf("%d ",b[i].p);
    38     return 0;
    39 }
  • 相关阅读:
    lbs(查看附近的人),看看社交软件如何实现查看附近的人
    PHP框架中的日志系统
    PHP链式操作输出excel(csv)
    看看你的正则行不行——正则优化一般的json字符串
    PHP设计模式(三)
    PHP设计模式(二)
    PHP设计模式(一)
    PHP守护进程
    数据库的常用日志
    浅谈数据库事物
  • 原文地址:https://www.cnblogs.com/autsky-jadek/p/4060264.html
Copyright © 2011-2022 走看看