The 2018 ACM-ICPC Asia Qingdao Regional Contest E Plants vs. Zombies (ZOJ 4062)

Topic links: https://zoj.pintia.cn/problem-sets/91827364500/problems/91827370312

Meaning of the questions: on the right there in your family n pieces of land, each land separated by one meter, the first piece of land separated by 1 meter away from home, and now you start from home robots go to the land watering, the robot moves one meter every time you pour water, the i-th block of land every once poured water will increase a [i] defense value, overall defense value n is the smallest pieces of land defense value, now you can only go robots m m m m asking you finish after the whole defense value is the maximum possible number.

Thinking: Defensive maximize conceivable half the minimum l = 0, the maximum r = 1e17, and the land for the i-th block, it is certainly the robot is moved back and forth between i and i + 1, until i reaches a respective block land value, i + 1 corresponding to the first piece of land will increase the number of watering.

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
typedef long long ll;
using namespace std;
ll a[200005];
ll fun(ll mid,ll n,ll m)
{
    ll sum=0;
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        ll x=mid/a[i];
        if(mid%a[i]!=0)
            X ++ ;
         IF (X <= SUM) // i-th has reached MID 
        {
            SUM = 0 ;
             IF (i <n-) // if i <n, the i-1 first is moved from the first to i, when i == n, will have reached a mid, no need to move 
               ANS ++ ;
        }
        else
        {
            X - = SUM; // number minus the required number of watering 
            ANS ANS + = 2 * X- . 1 ; // finished pouring the desired number of the i-th block 
            SUM = X- . 1 ; // corresponding to the i + pouring a sum Ci 
        }
         IF (ans> m) // If ans has become larger than m, and it is certainly not a 
            return  0 ;
    }
    if(ans>m)
        return 0;
    return 1;
}
int main ()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        ll n,m;
        scanf("%lld%lld",&n,&m);
        for(int i=1;i<=n;i++)
            scanf("%lld",&a[i]);
        ll l=0,r=100000000000000007;
        ll ans;
        while(l<=r)
        {
            MID LL = (L + R & lt) / 2 ;
             IF (MID == 0 ) // MID = 0 is certainly established, but there is not necessarily a function of fun to the establishment of the 
            {
                ans=mid;
                l=mid+1;
                continue;
            }
            if(fun(mid,n,m)==1)
            {
                ans=mid;
                l=mid+1;
            }
            else
                r=mid-1;
        }
        printf("%lld\n",ans);
    }
}

 

Guess you like

Origin www.cnblogs.com/zcb123456789/p/12336351.html