AtCoder Grand Contest 020 简要题解

A

int main()
{
int d=abs(a-b);
if (d&1) puts("Borys");
else puts("Alice");
return 0;
}


B

int n,a[100100];

int main()
{
if (a[n]!=2) {puts("-1");return 0;}
ll L,R;L=R=2;
per(i,n,1)
{
L=(L-1)/a[i]+1;R=R/a[i];
if (L>R) {puts("-1");return 0;}
L*=a[i];R=(R+1)*a[i]-1;
if (L>R) {puts("-1");return 0;}
}
printf("%lld %lld\n",L,R);
return 0;
}


C

int n;
bitset<4004000> f;

int main()
{
f[0]=1;int s=0;
rep(i,1,n)
{
f|=(f<<x);s+=x;
}
rep(i,(s+1)>>1,s)
{
if (f[i]) {printf("%d",i);break;}
}
return 0;
}


D

int a,b,c,d,k;

int chk(int mid)
{
if (!mid) return 1;
if (mid%(k+1)==0) return chk(mid-1);
int rsta=a-(mid-mid/(k+1)),rstb=b-mid/(k+1);
return rstb<=1ll*(rsta+1)*k;
}

int main()
{
while (q--)
{
k=(max(a,b)-1)/(min(a,b)+1)+1;
int l=0,r=a+b,pos=0;
while (l<=r)
{
int mid=(l+r)>>1;
if (chk(mid)) {pos=mid;l=mid+1;}
else r=mid-1;
}
rep(i,c,min(pos,d))
{
if (i%(k+1)) putchar('A');
else putchar('B');
}
rep(i,max(c,pos+1),d)
{
int tmp=a+b-i+1;
if (tmp%(k+1)) putchar('B');
else putchar('A');
}
puts("");
}
return 0;
}


E

$f_{l,r}=\sum_{k=l}^{r-1}g_{l,k}\times f_{k+1,r}\\ g_{l,r}=\sum_{d|r-l+1} [\mathrm{valid}(l,l+d-1)]f_{l,l+d-1}$

map<string,int> f,g;

int calcf(string);int calcg(string);

int calcg(string s)
{
if (g[s]) return g[s];
int n=s.size(),ans=0;
rep(d,1,n-1)
{
if (n%d) continue;
string t="";
rep(i,0,d-1)
{
int ch=1;
for (int j=i;j<n;j+=d) ch&=(s[j]-'0');
t=t+(char)(ch+'0');
}
ans=(ans+calcf(t))%maxd;
}
g[s]=ans;return ans;
}

int calcf(string s)
{
if (f[s]) return f[s];
int n=s.size(),ans=0;
rep(i,1,n)
ans=(ans+1ll*calcg(s.substr(0,i))*calcf(s.substr(i,n))%maxd)%maxd;
f[s]=ans;return ans;
}

int main()
{
string s;
cin >> s;
f[""]=1;
g[""]=1;g["0"]=1;g["1"]=2;
printf("%d",calcf(s));
return 0;
}


F

nb题，原本还以为是什么积分理论，最后居然能转成离散问题。

int n,m,l[7],id[7],f[310][310][130];

int main()
{
sort(l+1,l+1+n);
rep(i,1,n-1) id[i]=i;
int lim=(1<<(n-1))-1;
double ans=0.0;
while (1)
{
memset(f,0,sizeof(f));
f[0][l[n]*n][0]=1;
rep(i,1,n*m-1)
{
rep(j,i,n*m)
{
rep(sta,0,lim)
{
f[i][j][sta]+=f[i-1][j][sta];
int x=i%n;
if ((!x) || ((sta>>(x-1))&1)) continue;
int nxtj=min(n*m,max(j,i+l[id[x]]*n)),nxts=(sta|(1<<(x-1)));
f[i][nxtj][nxts]+=f[i-1][j][sta];
}
}
}
ans+=f[n*m-1][n*m][lim];
if (!next_permutation(id+1,id+n)) break;
}
rep(i,1,n-1) ans/=i;
rep(i,1,n-1) ans/=m;
printf("%0.15lf",ans);
return 0;
}

posted @ 2020-06-01 01:07  EncodeTalker  阅读(131)  评论(0编辑  收藏