M-SOLUTIONS Programming Contest

FROM

Sign (A is ans = 180 (n-2) thus hold the code)

#include<bits/stdc++.h>
using namespace std;
int n,ans;
char s[100001];
int main()
{
    scanf("%s",s+1);
    n=strlen(s+1),ans=15-n;
    for(int i=1;i<=n;i++)if(s[i]=='o')ans++;
    if(ans>=8)puts("YES");else puts("NO");
}
View Code

C

Consider enumeration loser win a few times, then know that you can expect a few rough i Bureau Bureau (just calculate this on the line)

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+7,mod=1e9+7;
int n,a,b,c,ans,fac[N],inv[N],pa[N],pb[N],s[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 ret;
}
int C(int a,int b){return 1ll*fac[a]%mod*inv[a-b]%mod*inv[b]%mod;}
int main()
{
    cin>>n>>a>>b>>c;
    a=1ll*a*qpow(100-c,mod-2)%mod;
    b=1ll*b*qpow(100-c,mod-2)%mod;
    c=1ll*c*qpow(100,mod-2)%mod;
    fac[0]=1;for(int i=1;i<=2*n;i++)fac[i]=1ll*fac[i-1]*i%mod;
    inv[2*n]=qpow(fac[2*n],mod-2);
    for(int i=2*n;i;i--)inv[i-1]=1ll*inv[i]*i%mod;
    pa[0]=pb[0]=1;for(int i=1;i<=2*n;i++)pa[i]=1ll*pa[i-1]*a%mod,pb[i]=1ll*pb[i-1]*b%mod;
    for(int i=1;i<=2*n;i++)s[i]=1ll*i*qpow(mod+1-c,mod-2)%mod;
    for(int i=0;i<n;i++)ans=(ans+(1ll*pa[i]*pb[n]+1ll*pa[n]*pb[i])%mod*s[i+n]%mod*C(i+n-1,i))%mod;
    cout<<ans<<endl;
}
View Code

D

Greedy, because the minimum will be counted, so every time the minimum can select a leaf node (statistics only once), and then deleting the leaf node, so you can actually find the optimal solution is in addition to each have a maximum value the answer is counted once, the structure is an array of c in descending order, according to the order assigned dfs (guaranteed son <father)

#include<bits/stdc++.h>
using namespace std;
const int N=1e4+7;
int n,ans,cnt,c[N],s[N];
vector<int>G[N];
void dfs(int u,int fa)
{
    s[u]=c[++cnt];
    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);
    for(int i=1;i<=n;i++)scanf("%d",&c[i]);
    sort(c+1,c+n+1),reverse(c+1,c+n+1);
    for(int i=2;i<=n;i++)ans+=c[i];
    printf("%d\n",ans);
    dfs(1,0);
    for(int i=1;i<=n;i++)printf("%d ",s[i]);
}
View Code

E

Oh, cheese! What mentally title! However, I would like to think of complicated derivative and integral to go! In fact, the practice is to divide each of a d, then that is even by the factorial.

#include<bits/stdc++.h>
using namespace std;
const int mod=1e6+3;
int x,d,n,fac[mod];
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 ret;
}
int main()
{
    fac[0]=1;for(int i=1;i<mod;i++)fac[i]=1ll*fac[i-1]*i%mod;
    int Q;scanf("%d",&Q);
    while(Q--)
    {
        scanf("%d%d%d",&x,&d,&n);
        if(!d)printf("%d\n",qpow(x,n));
        else{
            x=1ll*x*qpow(d,mod-2)%mod;
            if(!x||x+n-1>=mod)puts("0");
            else printf("%d\n",1ll*fac[x+n-1]*qpow(fac[x-1],mod-2)%mod*qpow(d,n)%mod);
        }
    }
}
View Code

F

Too hot, do not write.

result:rank200,rating+=30

Guess you like

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