8.9 NOIP simulation test 15 urban (city) + bombing (bomb) + rock-paper-scissors (rps)

Given the extent of the brutality T3, I decided to first take a decadent piece solution to a problem.

T1 urban (city)

Inclusion and exclusion method baffle +

Construction teams of m into n groups, each group must have a, is not considered an upper limit, a total of C (m-1, n-1) kinds of programs.

I-th groups of more than k, off-repellent capacity C (n, i) * C (mi * k-1, n-1) × k i corresponds to a construction teams out, the remaining mi * construction of k into n groups and teams to ensure that each group has at least one and no consideration bound, then this i-k into n packets where there are at least two groups is greater than i k.

#include<iostream>
#include<cstring>
#include<cstdio>
#define mod 998244353
#define ll long long
using namespace std;
ll n,m,k,fac[10001000],inv[10001000],facinv[10001000],ans;
ll C(ll x,ll y)
{
    if(y>x) return 0;
    return fac[x]*facinv[y]%mod*facinv[x-y]%mod;
}
int main()
{
    scanf("%lld%lld%lld",&n,&m,&k);
    if(n>m){
        puts("0");
        return 0;
    }
    fac[0]=1;facinv[0]=1;inv[1]=1;
    for(int i=1;i<=max(n,m);i++){
        if(i!=1) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
        fac[i]=fac[i-1]*i%mod;
        facinv[i]=facinv[i-1]*inv[i]%mod;
    }
    for(int i=1;i<=n;i++){
        if(i&1) ans=(ans+C(n,i)*C(m-i*k-1,n-1))%mod;
        else ans=(ans-C(n,i)*C(m-i*k-1,n-1)+mod)%mod;
    }
    printf("%lld\n",(C(m-1,n-1)-ans+mod)%mod);
    return 0;
}
city

 

T2 bombing (bomb)

Exam wrong a lot of questions, but I did not wrong to do it (is a waste)

As long as there is movement path can reach, then we point tarjan shrink, shrink after completion FIG build a new point, to find the longest chain, the depth of each point should be the parent node point + depth size (a few points lump together ), topu request longest chain, or dfs (dfs but seems to be easy T).

#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
struct node
{
    int to,nxt;
}h[4001000],hh[4001000];
int n,m,nxt[4001000],tot,tet,cnt,dfn[1001000],low[1001000],s[1001000];
int top,num,whos[1001000],sz[1001000],du[1001000],dep[1001000],ans,nx[4001000];
bool is[1001000];
int max ( int x, int y) 
{ 
    return x> y? x: y; 
} 
Void add ( int x, int y) 
{ 
    h [ ++ tot] .to = y; 
    h [tot] .nxt = nxt [x]; 
    nxt [x] = tot; 
} 
Void product ( int x, int y) 
{ 
    HH [ ++ tet] .to = y; 
    HH [tet] .nxt = NX [x]; 
    NX [x] = tet; 
} 
Void tarjan ( int x)
{
    dfn[x]=low[x]=++cnt;
    s[++top]=x;is[x]=1;
    for(int i=nxt[x];i;i=h[i].nxt){
        int y=h[i].to;
        if(!dfn[y]){
            tarjan(y);
            low[x]=min(low[x],low[y]);
        }
        else if(is[y]) low[x]=min(low[x],dfn[y]);
    }    
    if(dfn[x]==low[x]){
        num++;
        while(1){
            int tmp=s[top--];
            is[tmp]=0;
            whos[tmp]=num;
            sz[num]++;
            if(x==tmp) break;
        }
    }
}
void topu()
{
    queue<int>q;
    for(int i=1;i<=num;i++)
        if(du[i]==0) q.push(i),dep[i]=sz[i],ans=max(ans,dep[i]);
    while(q.size()){
        int x=q.front();q.pop();
        for(int i=nx[x];i;i=hh[i].nxt){
            int y=hh[i].to;
            du[y]--;
            dep[y]=max(dep[y],dep[x]+sz[y]);
            ans=max(ans,dep[y]);
            if(!du[y]) q.push(y);
        }
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    int u,v;
    for(int i=1;i<=m;i++){
        scanf("%d%d",&u,&v);
        add(u,v);
    }
    for(int i=1;i<=n;i++)
        if(!dfn[i]) tarjan(i);
    for(int i=1;i<=n;i++){
        for(int j=nxt[i];j;j=h[j].nxt){
            int y=h[j].to;
            if(whos[i]!=whos[y]){
                ad(whos[i],whos[y]);
                du[whos[y]]++;
            }
        }
    }
    topu();
    printf("%d\n",ans);
}
bomb

 

Guess you like

Origin www.cnblogs.com/jrf123/p/11328044.html