# 模拟52 考试总结

2021-09-15 07:34:08  阅读：23  来源： 互联网

### T1.异或

#include <bits/stdc++.h>
using namespace std;
#define int long long
int bit[62],g[62];
inline int get(int l)
{
int ans=0;
for(int i=0;i<l;i++)ans+=(i+1)*bit[l-1-i];
ans+=l+1;
return ans;
}
int dfs(int lim,int x,int s)
{
if(!x)return s+1;
int ans=0;
if((lim>>(x-1))&1)
{
ans+=g[x-1];
ans+=dfs(lim,x-1,s+1);
}
else ans+=dfs(lim,x-1,0);
return ans;
}
signed main()
{
bit[0]=1;for(int i=1;i<=60;i++)bit[i]=bit[i-1]*2;
g[0]=1;for(int i=1;i<=60;i++)g[i]=get(i);
int n;cin>>n;
cout<<dfs(n-1,60,0)<<endl;
return 0;
}


### T2.赌神

$\frac{(\sum_{i=1}^n x_i)!}{\prod_{i=1}^nx_i!}$

#include <bits/stdc++.h>
using namespace std;
const int mod=998244353;
const int N=1000050;
{
int x=0;char ch=getchar();
while(ch<'0'||ch>'9')ch=getchar();
while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return x;
}
int a[N],inv[N],n;
priority_queue <pair<int,int> > q;
signed main()
{
for(int i=1;i<=n;i++)
{
q.push(make_pair(a[i],i));
}
inv[1]=1;for(int i=2;i<=sum;i++)inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
int ww=1;
while(sum)
{
int x=q.top().second,w=q.top().first;q.pop();
ww=1ll*ww*inv[sum]%mod*w%mod*n%mod;
q.push(make_pair(w-1,x));sum--;
}
cout<<ww<<endl;
return 0;
}


### T3.路径

#include <bits/stdc++.h>
using namespace std;
const int N=1000050;
const int mod=998244353;
{
int x=0;char ch=getchar();
while(ch<'0'||ch>'9')ch=getchar();
while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return x;
}
inline int A(int x,int y){return x+y>=mod?x+y-mod:x+y;}
inline int P(int x,int y){return x-y>0?x-y:x-y+mod;}
struct node{
int from,to,next;
}a[2*N];
{
a[mm].from=x;a[mm].to=y;
}
int f[N][105],g[N][105],n,k;bool v[N];
void dfs1(int x)
{
v[x]=1;f[x][0]=1;
{
int y=a[i].to;
if(v[y])continue;
dfs1(y);
for(int j=1;j<=k;j++)
f[x][j]=A(A(f[x][j],f[y][j]),f[y][j-1]);
f[x][0]=A(f[x][0],f[y][0]);
}
}
void dfs2(int x)
{
v[x]=1;
{
int y=a[i].to;
if(v[y])continue;
for(int j=0;j<=k;j++)
{
int f1=0,f2=0;
f1=P(P(g[x][j],f[y][j]),((j-1>=0)?f[y][j-1]:0));
f2=P(((j-1>=0)?P(g[x][j-1],f[y][j-1]):0),((j-2>=0)?f[y][j-2]:0));
g[y][j]=A(A(f[y][j],f1),f2);
}
dfs2(y);
}
}
int sit[105][105],jc[105];
signed main()
{
for(int i=1;i<n;i++)
{
}
dfs1(1);memset(v,0,sizeof(v));
for(int i=0;i<=k;i++)g[1][i]=f[1][i];
dfs2(1);
sit[0][0]=jc[0]=1;
for(int i=1;i<=k;i++)
{
sit[i][0]=0;
for(int j=1;j<=i;j++)
sit[i][j]=A(1ll*j*sit[i-1][j]%mod,sit[i-1][j-1]);
jc[i]=1ll*jc[i-1]*i%mod;
}
int ans=0;
for(int i=1;i<=n;i++)for(int j=0;j<=k;j++)
ans=A(ans,1ll*sit[k][j]*jc[j]%mod*g[i][j]%mod);
cout<<1ll*ans*499122177%mod;
return 0;
}