zoukankan      html  css  js  c++  java
  • Codeforces Round #625 Div. 1 Problem C

    Problem C - World of Darkraft: Battle for Azathoth

    Roma is playing a new expansion for his favorite game World of Darkraft. He made a new character and is going for his first grind.
    Roma has a choice to buy exactly one of n different weapons and exactly one of m different armor sets. Weapon i has attack modifier ai and is worth cai coins, and armor set j has defense modifier bj and is worth cbj coins.
    After choosing his equipment Roma can proceed to defeat some monsters. There are p monsters he can try to defeat. Monster k has defense xk, attack yk and possesses zk coins. Roma can defeat a monster if his weapon’s attack modifier is larger than the monster’s defense, and his armor set’s defense modifier is larger than the monster’s attack. That is, a monster k can be defeated with a weapon i and an armor set j if ai>xk and bj>yk. After defeating the monster, Roma takes all the coins from them. During the grind, Roma can defeat as many monsters as he likes. Monsters do not respawn, thus each monster can be defeated at most one.
    Thanks to Roma’s excessive donations, we can assume that he has an infinite amount of in-game currency and can afford any of the weapons and armor sets. Still, he wants to maximize the profit of the grind. The profit is defined as the total coins obtained from all defeated monsters minus the cost of his equipment. Note that Roma must purchase a weapon and an armor set even if he can not cover their cost with obtained coins.
    Help Roma find the maximum profit of the grind.
    Input
    The first line contains three integers n, m, and p (1≤n,m,p≤2⋅105) — the number of available weapons, armor sets and monsters respectively.
    The following n lines describe available weapons. The i-th of these lines contains two integers ai and cai (1≤ai≤106, 1≤cai≤109) — the attack modifier and the cost of the weapon i.
    The following m lines describe available armor sets. The j-th of these lines contains two integers bj and cbj (1≤bj≤106, 1≤cbj≤109) — the defense modifier and the cost of the armor set j.
    The following p lines describe monsters. The k-th of these lines contains three integers xk,yk,zk (1≤xk,yk≤106, 1≤zk≤103) — defense, attack and the number of coins of the monster k.
    Output
    Print a single integer — the maximum profit of the grind.
    Example
    inputCopy
    2 3 3
    2 3
    4 7
    2 4
    3 2
    5 11
    1 2 4
    2 1 6
    3 4 6
    outputCopy
    1
    题目意思有多个武器和多个防护的(英语差, ) 物品, 只能各自挑选一个,每个有两种属性,然后去打怪, 如果满足题目中给的条件ai>xk and bj>yk , 就能打倒这个怪物, 然后获得金币(有多少要满足此条件怪物 , 便可以打多少)
    求最大收获为多少

    首先对于物品, 怪物没有特殊要求, 我们先排序, 这样方便解题
    思路:枚举每一个盾牌 , 这个盾牌可以打倒比他低的怪兽 ,同时考虑它打倒的怪物, 看看武器打倒他的最小值, 然后武器值只要大于等于它的都满足条件, 这个时候我们找到了三个条件:枚举的此盾牌, 可以被盾牌打倒的怪物, 还有符合条件的武器范围(大于最小值) , 然后就在这三个条件中求最值
    对于盾牌可以打倒的怪物们来说, 可以获得的金币为C[k].c , 然后花费为盾牌和武器, 因为盾牌时枚举的, 最后剪掉就行, 假设此怪物被打倒获得金币a , 则将a加到武器范围大于最小值的, 因为大于最小值的武器皆可以被使用, 然后求最值 , 将此盾牌能打到的怪物全部这样处理 ,
    用到的数据结构:范围加一个值, 全局最大值、

    
    ```cpp
    #include <bits/stdc++.h>
    using namespace std ;
    const int N = 2e5 + 10 ;
    typedef long long ll ;
    ll a[N * 4] , lazy[N * 4] ;
    void down(int x)
    {
      if(lazy[x])
       {
         a[x << 1] += lazy[x] ;
         a[x << 1 | 1] += lazy[x] ;
         lazy[x << 1] += lazy[x] ;
         lazy[x << 1 | 1] += lazy[x] ;
         lazy[x] = 0 ;
       }
    }
    ll ha[N] ;
    void update(int rt , int l , int r , int L , int R , int v)
    {
      if(l == L && r == R)
       {
         lazy[rt] += v ;
         a[rt] += v ;
         return ;
       }
       down(rt) ;
       int mid = (l + r) >> 1 ;
       if(R <= mid) update(rt << 1 , l , mid , L , R , v) ;
       else if(L > mid)update(rt << 1 | 1 , mid + 1 , r , L , R , v) ;
       else
        {
          update(rt << 1 , l , mid , L , mid , v) ;
          update(rt << 1 | 1 , mid + 1 , r , mid + 1 , R , v) ;
        }
        a[rt] = max(a[rt << 1] , a[rt << 1 | 1]) ;
    }
    struct node
    {
      int a , b , c ;
    }A[N] , B[N] , C[N] ;
    bool cmp1(node a , node b)
    {
      return a.a < b.a ;
    }
    bool cmp2(node a , node b)
    {
      return a.b < b.b ;
    }
    int main()
    {
      int n , m , p ;
      scanf("%d%d%d" , &n , &m , &p) ;
      for(int i = 1; i <= n ;i ++) scanf("%d%d" , &A[i].a , &A[i].b ) ;
      for(int i = 1; i <= m ;i ++) scanf("%d%d" , &B[i].a , &B[i].b ) ;
      for(int i = 1; i <= p ;i ++) scanf("%d%d%d" , &C[i].a , &C[i].b , &C[i].c) ;
      sort(A + 1 , A + n + 1 , cmp1) , sort(B + 1 , B + m + 1 , cmp1) ;
      sort(C + 1 , C + p + 1 , cmp2) ;
      for(int i = 1; i <= n ;i ++)
       ha[i] = A[i].a , update(1 , 1 , n , i , i , -A[i].b) ;
      ll k = 1 , ans = -1e18 ;
      for(int i = 1; i <= m ;i ++)
       {
         while(k <= p && C[k].b < B[i].a)
          {
            int a = upper_bound(ha + 1 ,ha + n + 1 , C[k].a) - ha  ;
            if(a <= n) update(1 , 1 , n , a , n , C[k].c) ;
            k ++ ;
          }
          ans = max(ans , 1ll * a[1] - B[i].b) ;
       }
      cout << ans << endl ;
      return 0 ;
    }
    
    
    
    
    每次做题提醒自己:题目到底有没有读懂,有没有分析彻底、算法够不够贪心、暴力够不够优雅。
  • 相关阅读:
    day35-python-网络编程
    oc-继承(inherit) 方法重写 继承与组合
    oc-self关键字
    oc-类方法
    oc-封装 get set方法
    oc-匿名对象
    oc-函数命名
    oc-函数,方法,类
    解决"authentication token manipulation error"
    让tomcat自动定位到项目
  • 原文地址:https://www.cnblogs.com/spnooyseed/p/12870861.html
Copyright © 2011-2022 走看看