其他分享
首页 > 其他分享> > D. For Gamers. By Gamers.(前缀和)

D. For Gamers. By Gamers.(前缀和)

作者:互联网

D. For Gamers. By Gamers.

Tag

前缀和 rating2000

题目来源

Educational Codeforces Round 125 (Rated for Div. 2)

题目大意

解题思路

\[\frac{D_j}{h_i} \lt \frac{d_i}{H_j} *x \]

移项,得到

\[d_i * h_i * x > D_j * H_j \]

由此可见,我们只需要关注每个勇士或者恶魔的攻击力和生命值的乘积即可

\[\frac{C}{1} + \frac{C}{2} + \dot + \frac{C}{C} = C\log C \]

对于没有访问到的数据,我们可以用前缀和求出

AC代码

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define maxn (int)(1e6 + 10)
#define IOS ios::sync_with_stdio(0);
#define FFF freopen("out", "w", stdout);



int n , C ;
int m ;
LL bst[maxn];

LL ans[maxn];




int main ()
{
    IOS;
    cin >> n >> C ;
    for ( int i = 1 ; i <= n ; i++ )
    {
        LL c , d , h;
        cin >> c >> d >> h;
        bst[c] = max(bst[c], d*h);
    }

    for ( int c = 1 ; c <= C ; c++ )
        for ( int xc = c ; xc <= C ; xc += c )
            bst[xc] = max(bst[xc], bst[c] * (xc/c));
    for ( int i = 1 ; i <= C ; i++ )
        bst[i] = max(bst[i], bst[i-1]);

    cin >> m ;
    for ( int i = 1 ; i <= m ; i++ )
    {
        LL D , H;
        cin >> D >> H;
        int pos = upper_bound(bst+1, bst+1+C, D*H) - bst;
        if ( pos == C+1 )
            ans[i] = -1;
        else ans[i] = pos;
    }
    for ( int i = 1 ; i <= m ; i++ )
        cout << ans[i] << " ";
    cout << endl;
}

标签:frac,Gamers,攻击力,int,bst,恶魔,勇士,前缀
来源: https://www.cnblogs.com/I-wanna-be-the-kid/p/16058713.html