ZROI#1003

时间:2019-09-15
本文章向大家介绍ZROI#1003,主要包括ZROI#1003使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

ZROI#1003

这题显然可以\(\Theta(n\times max_{value})\)模拟.
也显然可以简单的解决\(m=1\)\(m=0\)的部分分.
\(m=0\)排个序从小到大直接计算即可.\(m=1\)需要考虑用哪一种魔法.
显然,怪物个数大于等于\(3\)个一定是\(AOE\)魔爆术比较优.
如果只有一个怪,直接神圣惩击.
两个怪要讨论,如果一个怪只有一滴血肯定魔爆比较优.否则神惩.
延续上面的考虑方法,我们如此贪心即可.
只要剩下的怪大于等于三个,就魔爆.
小于等于两个的情况参照上面的讨论即可.
于是,我们可以用堆维护,也可以用什么别的奇技淫巧.
但不管哪种方法,魔爆的影响肯定不能直接暴力修改.
正常人都应该会维护一个全局标记吧.
我选择了堆,但我的做法和上述做法有些许不同.
而且我能把自己叉掉,但是它\(A\)了...我就不管了
\(Hack:\)
\(Input:\)

3 10
1 4 4

\(Output:\)

5

\(Wrong \:Answer:\)

6

\(Code:\)

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define MEM(x,y) memset ( x , y , sizeof ( x ) )
#define rep(i,a,b) for (int i = (a) ; i <= (b) ; ++ i)
#define per(i,a,b) for (int i = (a) ; i >= (b) ; -- i)
#define pii pair < int , int >
#define X first
#define Y second
#define rint read<int>
#define int long long
#define pb push_back

using std::queue ;
using std::set ;
using std::pair ;
using std::max ;
using std::min ;
using std::priority_queue ;
using std::vector ;
using std::swap ;
using std::sort ;
using std::unique ;
using std::greater ;

template < class T >
    inline T read () {
        T x = 0 , f = 1 ; char ch = getchar () ;
        while ( ch < '0' || ch > '9' ) {
            if ( ch == '-' ) f = - 1 ;
            ch = getchar () ;
        }
       while ( ch >= '0' && ch <= '9' ) {
            x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ;
            ch = getchar () ;
       }
   return f * x ;
}

const int N = 1e5 + 100 ;
priority_queue < int , vector < int > , greater < int > > q ;
int n , m , tag , ans , v[N] ;

signed main (int argc , char * argv[]) {
    n = rint () ; m = rint () ;
    rep ( i , 1 , n ) { v[i] = rint () ; q.push ( v[i] ) ; }
    while ( ! q.empty () ) {
        if ( m ) {
            -- m ;
            if ( q.size () >= 3 ) {
                ++ tag ; while ( q.top () - tag <= 0 ) q.pop () ;
                ans += q.size () ;
            } else {
                int tmp = q.top () ; q.pop () ;
                if ( tmp - tag <= 1 ) {
                    ans += q.size () ;
                    ++ m ; continue ;
                }
                if ( tmp - tag > 2 ) q.push ( tmp - 2 ) ;
                ans += q.size () ;
            }
        } else {
            int tmp = q.top () ;
            ans += q.size () * ( tmp - tag - 1 ) + q.size () - 1 ;
            q.pop () ;
        }
    }
    printf ("%lld\n" , ans ) ;
    return 0 ;
}

原文地址:https://www.cnblogs.com/Equinox-Flower/p/11523759.html