Problem solution [water] happy Luogu6022

\[ Preface \]

Probably been out of that way six months ago (((

Then the day reading this title, to write their own std changed a bit ll and opinions A special judge handed the information.

Pick up a bargain.
\ [Description \]
you started with a \ (n \) bottles of water fun.

There \ (m \) th accessories, every bottle of drinking water can be obtained which joy \ (m \) a respective accessories \ (1 \) a, if \ (a [i] \) th accessories \ (i \) , will be happy pulls a bottle of water.

Q. A total of how many bottles of drinking water can be happy. If the unlimited white prostitute on output Inf.
\ [Solution \]
bottle bottle of water apparently will deal with TLE happy, so happy we have to deal with bulk water.

\(~\)

We open a barrel cnt[x]for "Accessories \ (x \) number."

Every time we deal with the current batch of \ (n \) bottles of water fun:

  1. So ans += n, it indicates drank current \ (n \) bottles of water fun.
  2. So cnt[i] += n, this indicates to obtain \ (m \) a respective accessories \ (n-\) a.
  3. Order n += cnt[i] / a[i], cnt[i] %= a[i], expressed happiness to be able to change the water have changed.

Until \ (n-0 = \) , this time \ (ANS \) is the desired.

\(~\)

Of course, there are infinite joy white whore of water, in this case, \ (the n-\) is never equal to \ (0 \) , which means that water will drink more and more happy.

Little analysis of what we found: if not unlimited white prostitute, at any time the number of water will not be happy than or equal to the initial given \ (the n-\) .

Think about it, if you can infinitely white prostitute, is equivalent to saying that you use \ (n \) bottles of water after several rounds happy transformation, change to the \ (k \) \ ((the n-\ Leq k) \) bottles of water fun , then you again in this \ (k \) bottles of water fun elect \ (n \) bottles of water and then several rounds happy transformation, they can get \ (k \) bottles of water fun, and so forth, you can always white happy prostitute water.

Thus with the above properties can be determined whether the water unlimited Happy white abusers.
\ [Code \]

#include<cstdio>

#define RI register int

using namespace std;

inline int read()
{
    int x=0,f=1;char s=getchar();
    while(s<'0'||s>'9'){if(s=='-')f=-f;s=getchar();}
    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
    return x*f;
}

const int N=100100,M=10;

int n,m,lim;

int a[N],cnt[M];

long long ans;

int main()
{
    n=read(),m=read();

    lim=n;

    for(RI i=1;i<=m;i++)
        a[i]=read();

    while(n)
    {
        ans+=n;

        for(RI i=1;i<=m;i++)
            cnt[i]+=n;

        n=0;

        for(RI i=1;i<=m;i++)
            n+=cnt[i]/a[i],cnt[i]%=a[i];

        if(n>=lim)
        {
            puts("Inf");
            return 0;
        }
    }

    printf("%lld\n",ans);

    return 0;
}

\[ Thanks \ for \ watching \]

Guess you like

Origin www.cnblogs.com/cjtcalc/p/12244206.html