Comet OJ - Contest #5

A

Attendance

#include<bits/stdc++.h>
using namespace std;
char s[200002];
int n,a[20];
int main()
{
    scanf("%s",s+1);
    n=strlen(s+1);
    for(int i=1;i<=n;i++)a[s[i]-'0']++;
    int ans=min(min(a[1]/3,a[4]/2),a[5]);
    cout<<ans<<endl;
}
View Code

B

Easily found 2f (x) <= 2 * 9 * 18 = 324, the enumeration <= 324 legitimate factor to (Actually, only to enumerate 9 * 2 * 2 = 36), but the pretreatment legitimate factor complex I the same degree.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
bool Show [ 325 ];
vector<int>G;
int judge(int x)
{
    int fx=x%10+x/10%10+x/100;
    return fx==x/2;
}
int main ()
{
    int Q;scanf("%d",&Q);
    for(int i=1;i<=324;i++)if(judge(i))G.push_back(i);
    while(Q--)
    {
        scanf("%lld",&n);
        int ans=0;
        for(int i=0;i<G.size();i++)if(n%G[i]==0)ans++;
        printf("%d\n",ans);
    }
}
View Code

C

Recording a pointer to a minimum depth of the current can be put, and then there is all the possible points in the set to make trouble on the line

#include<bits/stdc++.h>
using namespace std;
const int N=5e5+7;
int n,mx,sum[N],dep[N],a[N];
vector<int>G[N],vec[N];
set<int>S;
void dfs(int u,int fa)
{
    dep[u]=dep[fa]+1;
    mx=max(mx,dep[u]),vec[dep[u]].push_back(u);
    for(int i=0;i<G[u].size();i++)if(G[u][i]!=fa)dfs(G[u][i],u);
}
int main ()
{
    scanf("%d",&n);
    for(int i=1,x,y;i<n;i++)scanf("%d%d",&x,&y),G[x].push_back(y),G[y].push_back(x);
    dfs(1,0);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]),sum[a[i]+1]++;
    int p=1;
    while(p<=n&&!sum[p])
    {
        for(int i=0;i<vec[p].size();i++)S.insert(vec[p][i]);
        p++;
    }
    for(int i=1;i<=n;i++)
    {
        int u = * S.begin (); S.erase (u);
        printf("%d ",u);
        sum[a[u]+1]--;
        while(p<=n&&!sum[p])
        {
            for(int i=0;i<vec[p].size();i++)S.insert(vec[p][i]);
            p++;
        }
    }
}
View Code

D

It is said CZDdalao violence O (nq) over? tql! But I will not, not being revised.

E

Or not, Lnoi2019 did not know how much a simplified version, however, and this idea sweeps clean. p is the probability of a single disappeared, q is a single probability does not disappear when the individual is provided with i, the probability of the first individual is finally disappeared F [i], then the probability of the first person is the disappearance of the j-th pq J (. 1 Q- J ) I-. 1 , and then expand the binomial theorem then summed with geometric series, to obtain F [I] = pΣC (. 1-I, J-. 1) (-. 1) J. 1- / (. 1 Q- J ), then the number of combinations of items removed, NTT can be evaluated. Then the probability Resetting individual person i n finally disappeared is G [i], i-1 is substantially equal to the front for an individual, the first individual humans remaining finally disappeared, so there g [i] = ΣC ( . 1-I, J) P I Q n--I. 1- F [NJ], the same number of combinations that may be removed to solve items + NTT. Complexity of O (nlogn)

#include<bits/stdc++.h>
using namespace std;
const int N=804000,mod=998244353;
int n,nn,p,q,fac[N],inv[N],R[N],a[N],b[N],c[N],d[N];
int qpow(int a,int b)
{
    int ret=1;
    while(b)
    {
        if(b&1)ret=1ll*ret*a%mod;
        a=1ll*a*a%mod,b>>=1;
    }
    Return the right;
}
void NTT(int*a,int f)
{
    for(int i=0;i<nn;i++)if(i<R[i])swap(a[i],a[R[i]]);
    for(int i=1;i<nn;i<<=1)
    {
        int wn=qpow(3,mod/(i<<1));
        if(f==-1)wn=qpow(wn,mod-2);
        for(int j=0;j<nn;j+=i<<1)
        for(int k=0,w=1;k<i;k++,w=1ll*w*wn%mod)
        {
            int x=a[j+k],y=1ll*a[i+j+k]*w%mod;
            A [j + k] = (x + y) v%, a [i + j + k] = (x-y + v)% v;
        }
    }
    if(f==1)return;
    int invn=qpow(nn,mod-2);
    for(int i=0;i<nn;i++)a[i]=1ll*a[i]*invn%mod;
}
int main ()
{
    fac[0]=1;for(int i=1;i<N;i++)fac[i]=1ll*fac[i-1]*i%mod;
    inv[N-1]=qpow(fac[N-1],mod-2);for(int i=N-1;i;i--)inv[i-1]=1ll*inv[i]*i%mod;
    scanf("%d%d%d",&n,&p,&q),p=1ll*p*qpow(q,mod-2)%mod,q=(mod+1-p)%mod;
    int L=0;for(nn=1;nn<=(n<<1);nn<<=1)L++;
    for(int i=0;i<nn;i++)R[i]=(R[i>>1]>>1)|((i&1)<<L-1);
    for(int i=0;i<=n;i++)
    {
        a[i]=1ll*fac[i]*(1-qpow(q,i+1)+mod)%mod;
        a[i]=qpow(a[i],mod-2);
        if(i&1)a[i]=mod-a[i];
        if(i)b[i]=inv[i-1];
    }
    NTT(a,1),NTT(b,1);
    for(int i=0;i<nn;i++)a[i]=1ll*a[i]*b[i]%mod;
    NTT(a,-1);
    for(int i=0;i<=n;i++)a[i]=1ll*a[i]*p%mod*fac[i-1]%mod;
    for(int i=0;i<=n;i++)
    {
        c[i]=1ll*a[n-i]*qpow(p,i)%mod*inv[i]%mod;
        if(i)d[i]=1ll*qpow(q,i-1)*inv[i-1]%mod;
    }
    NTT(c,1),NTT(d,1);
    for(int i=0;i<nn;i++)c[i]=1ll*c[i]*d[i]%mod;
    NTT(c,-1);
    for(int i=1;i<=n;i++)printf("%d\n",1ll*c[i]*fac[i-1]%mod);
}
View Code

result: rank30, or too dishes

 

Guess you like

Origin www.cnblogs.com/hfctf0210/p/11026997.html