Codeforce 1296 D. Fight with Monsters

有n个怪兽以及他们的血量h_i,A和B两个人要杀死所有怪兽,他们的攻击力分别为a和b。对于每一个怪兽,A,B轮流攻击,A总是先手,如果在A攻击的过程中怪兽死亡,A得1分;在B攻击的过程中怪兽死亡,A不得分。A可以跳过B攻击的回合k次,就是这k次B不对怪兽进行攻击,问A最多能得多少分。

h_i\left ( a+b \right )取模,这些血量让A,B轮流攻击,只有最后一回合才影响得分。

h_i mod = (a+b) 

c_i表示对于第i个怪兽,需要跳过多少B的回合A才能杀死他得分,c_i=ceil(h_i/a)-1

c_i从小到大排序,依次让k-=c_i直到k<c_i即可。

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#define ms(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef double ab;
const int N=1e6+10;
// int h[N];
vector<int>res;
int main()
{
    int n,a,b,k,ans=0;
    cin>>n>>a>>b>>k;
    for(int i=0,h;i<n;i++)
    {
        cin>>h;
        h%=(a+b);
        if(h==0) h=a+b;
        res.push_back(ceil((double)h/a)-1);
    }
    sort(res.begin(),res.end());
    for(int i=0;i<res.size();i++)
    {
        if(res[i]<=k)
        {
            ++ans;
            k-=res[i];
        }
    }
    cout<<ans<<endl;
    //system("pause");
}

猜你喜欢

转载自blog.csdn.net/Luowaterbi/article/details/104183830
今日推荐