A.Find Divisible

沙比题

显然l和2*l可以直接满足条件。

代码

#include<iostream>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#define N 110000
#define L 100000
#define eps 1e-7
#define inf 1e9+7
#define db double
#define ll long long
#define ldb long double
using namespace std;
inline ll read()
{
char ch=0;
ll x=0,flag=1;
while(!isdigit(ch)){ch=getchar();if(ch=='-')flag=-1;}
while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
return x*flag;
}
int main()
{
ll t=read();
for(ll i=1;i<=t;i++)
{
ll l=read(),r=read();
cout<<l<<" "<<2*l<<endl;
}
return 0;
}

B.Substring Removal

细节题

分类讨论一下

先看一下是否整个字符串为同一种字符,此时答案为子串个数,特判掉。

如果不满足,则求出最长的前、后缀满足字符相等。

分别设为a,b。

ans=1+a+b+a*b(1为删除整个串的情况)

代码

#include<iostream>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#define N 1100000
#define L 1000000
#define eps 1e-7
#define inf 1e9+7
#define db double
#define ll long long
#define ldb long double
using namespace std;
inline ll read()
{
char ch=0;
ll x=0,flag=1;
while(!isdigit(ch)){ch=getchar();if(ch=='-')flag=-1;}
while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
return x*flag;
}
const ll mo=998244353;
char s[N];
int main()
{
ll n=read(),a=0,b=0,ans=1;
scanf("%s",s+1);if(n==1){printf("1");return 0;}
a=1;while(a<n&&s[a]==s[a+1])a++;ans+=a;
b=n;while(b>1&&s[b]==s[b-1])b--;ans+=n-b+1;
if(a==n&&b==1){cout<<(((n*(n-1)/2))%mo);return 0;}
if(s[1]==s[n])
{
ans=(ans+((a*(n-b+1))%mo))%mo;
cout<<ans%mo;
return 0;
}
else
{
cout<<ans%mo;
return 0;
}
return 0;
}

C.Polygon for the Angle

数论题

首先可以发现



类似x和y这样的角是相等的。(可以构造外接圆,然后利用等弦对等角证明)

考虑计算这种角的大小

(n-2)*180/n是一个内角的大小,再除以n-2即为这种角的大小。

显然,n边形合法的条件是n/180|ang

当然可以直接数论强推。

这里讲一个简单的做法。

就是直接枚举n,强行判断一下即可。

需要注意的是,即使满足了整除这个条件,仍然有可能不合法。

比如第四个样例

query:178

answer:180

答案不是90的原因是90边形虽然满足了整除这个条件,但是最大的角也只有176°。

注意一下这个问题即可。

#include<iostream>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#define N 110000
#define L 100000
#define eps 1e-7
#define inf 1e9+7
#define db double
#define ll long long
#define ldb long double
using namespace std;
inline ll read()
{
char ch=0;
ll x=0,flag=1;
while(!isdigit(ch)){ch=getchar();if(ch=='-')flag=-1;}
while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
return x*flag;
}
int main()
{
ll t=read();
for(ll o=1;o<=t;o++)
{
ll ang=read();
bool flag=false;
for(ll i=1;i<=400;i++)
{
ldb x=180.0/(ldb)i,k=(ldb)ang/x;
if((180.0-x*2.0>=(ldb)ang)&&(fabs(k-(ll)k)<=0.0001||fabs(k-(ll)k)>=0.9999))
{
cout<<i<<endl;
flag=true;break;
}
}
if(!flag)printf("-1\n");
}
return 0;
}

D.Easy Problem

垃圾dp题

直接dp[i][j]表示放了i个数匹配hard匹配到了第j位。

每次决策有两种。

删除:代价ai,强制j保持不变。

不删除:无代价,j根据s[i]是否和j+1匹配来决定是否+1。

代码

#include<iostream>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#define N 150000
#define L 100000
#define eps 1e-7
#define inf 1e18+7
#define db double
#define ll long long
#define ldb long double
using namespace std;
inline ll read()
{
char ch=0;
ll x=0,flag=1;
while(!isdigit(ch)){ch=getchar();if(ch=='-')flag=-1;}
while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
return x*flag;
}
ll n,a[N],dp[N][5];
char s[N],ch[5]={'0','h','a','r','d'};
ll dfs(ll x,ll k)
{
if(x==n+1)return 0;
if(dp[x][k]!=-1)return dp[x][k];
dp[x][k]=inf;
if(s[x]==ch[k+1])
{
if(k!=3)dp[x][k]=min(dp[x][k],dfs(x+1,k+1));
}
else dp[x][k]=min(dp[x][k],dfs(x+1,k));
dp[x][k]=min(dp[x][k],dfs(x+1,k)+a[x]);
return dp[x][k];
}
int main()
{
n=read();scanf("%s",s+1);
for(ll i=1;i<=n;i++)a[i]=read();
memset(dp,-1,sizeof(dp));
cout<<dfs(1,0);
return 0;
}

E.The Top Scorer

组合,容斥,概率。

考虑枚举最大值和最大值的个数,分别设为o,i。

发现满足这个条件的方案数=c(n,i)f(n-i,s-io,o)

f(i,j,k)函数的意义是把和为j的数字分配给i个人,每个人的数字严格<k的方案数。

这个也就等价于sigema xi=j (xi<k)的解的个数。

这是一个经典的容斥题。

容斥的大体思路就是枚举至少有几个人的数值>=k(即不合法的个数)

用插板法去计算。

计算的复杂度为O(n)(n为人数个数)

考虑计算出来的方案数,对于有i个最大值的情况,每一种方案都有1/i的概率是第一个人获胜。

对总概率的贡献需要乘上一个1/i。

最终再除以一下总方案数即可(插板法计算)

代码

#include<iostream>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#define N 220000
#define L 200000
#define eps 1e-7
#define inf 1e9+7
#define db double
#define ll long long
#define ldb long double
using namespace std;
inline ll read()
{
char ch=0;
ll x=0,flag=1;
while(!isdigit(ch)){ch=getchar();if(ch=='-')flag=-1;}
while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
return x*flag;
}
const ll mo=998244353;
ll ksm(ll x,ll k)
{
ll ans=1;
while(k)
{
if(k&1)ans=(ans*x)%mo;
k>>=1;
x=(x*x)%mo;
}
return ans;
}
ll fac[N],vac[N];
ll inv(ll x){return ksm(x,mo-2);}
ll c(ll n,ll m){return (fac[n]*((vac[m]*vac[n-m])%mo))%mo;}
int main()
{
ll n=read(),s=read(),r=read(),ans=0;
if(n==1){printf("1");return 0;}
fac[0]=vac[0]=1;for(ll i=1;i<=L;i++)fac[i]=(fac[i-1]*i)%mo,vac[i]=(vac[i-1]*inv(i))%mo;
for(ll o=r;o<=s;o++)for(ll i=1;i<=n&&i*o<=s;i++)
{
ll m=n-i,v=s-i*o,x=0;
for(ll k=0,flag=1;k<=m&&v-k*o>=0;k++,flag=-flag)
x=(x+flag*c(m,k)*c(v-k*o+m-1,m-1))%mo;
if(!m&&!v)x=1;
ans=(ans+((inv(i)*((c(n-1,i-1)*x)%mo))%mo))%mo;
}
ans=(ans*inv(c(s-r+n-1,n-1)))%mo;
cout<<ans;
return 0;
}

F.Inversion Expectation

概率,期望。

根据期望是线性函数这一性质,拆开算。

已知和已知的逆序对。

未知和未知的逆序对。

已知和未知的逆序对。

前两个都是非常好计算的。

计算第三个的时候。

考虑每一个已知的数字x。

设它左边有a个数未知,右边有b个数未知

再设共有k个比它小的数字未知。

显然这k个数相对x来说应该等概率分布。

左边期望有ka/(a+b)个,右边有kb/(a+b)个。

算一下即可。

G.Lucky Tickets

多项式模板题

发现题意就是让你先算出长度为n/2,和为k,(k<=n/2✖10)的方案数。

然后再乘法原理搞一搞。

考虑怎么计算和为k的方案数。

考虑暴力dp,用分治实现。

dp[n][k]=sigema dp[n/2][i]*dp[n/2][k-i]

(如果n为奇数,还需要再卷上一个dp[1])

显然这是一个卷积的形式。

进一步的,发现这是一个多项式幂的形式。

直接分治+ntt即可。

代码

#include<iostream>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#define N 4400000
#define L 4000000
#define eps 1e-7
#define inf 1e9+7
#define ll long long
using namespace std;
inline int read()
{
char ch=0;
int x=0,flag=1;
while(!isdigit(ch)){ch=getchar();if(ch=='-')flag=-1;}
while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
return x*flag;
}
const ll d=3,mo=998244353;
ll ksm(ll x,ll k)
{
ll ans=1;
while(k)
{
if(k&1)ans=(ans*x)%mo;
k>>=1;
x=(x*x)%mo;
}
return ans;
}
int rev[N];
void ntt(ll *f,int n,int flag)
{
ll t,w,wn;
int i,j,k,kk;
for(i=0;i<n;i++)rev[i]=(rev[i>>1]>>1)+((i&1)*(n>>1));
for(i=0;i<n;i++)if(i<rev[i])swap(f[i],f[rev[i]]);
for(k=2,kk=1;k<=n;k<<=1,kk<<=1)
{
wn=ksm(d,(mo-1)/k);
if(flag==-1)wn=ksm(wn,mo-2);
for(i=0;i<n;i+=k)
for(j=0,w=1;j<kk;j++,w=(w*wn)%mo)
{
t=(w*f[i+j+kk])%mo;
f[i+j+kk]=(f[i+j]-t+mo)%mo;
f[i+j]=(f[i+j]+t)%mo;
}
}
if(flag==-1)
{
ll inv=ksm(n,mo-2);
for(int i=0;i<n;i++)f[i]=(f[i]*inv)%mo;
}
}
ll a[N],b[N],f[N],g[N];
void solve(int n)
{
if(n==1)return;
solve(n/2);
int len;
for(len=1;len<=n*10;len<<=1);for(int i=0;i<len;i++)a[i]=f[i];
ntt(a,len,+1);for(int i=0;i<len;i++)a[i]=(a[i]*a[i])%mo;ntt(a,len,-1);
for(int i=0;i<len;i++)f[i]=a[i];
if(n&1)
{
for(len=1;len<=n*10;len<<=1);
for(int i=0;i<len;i++)a[i]=f[i],b[i]=g[i];
ntt(a,len,+1);ntt(b,len,+1);
for(int i=0;i<len;i++)a[i]=(a[i]*b[i])%mo;
ntt(a,len,-1);
for(int i=0;i<len;i++)f[i]=a[i];
}
}
int main()
{
int n=read()/2,k=read(),x;
for(int i=1;i<=k;i++)x=read(),f[x]=g[x]=1;
solve(n);
ll ans=0;
for(int i=0;i<=n*10;i++)ans=(ans+((f[i]*f[i])%mo))%mo;
cout<<ans;
return 0;
}

Educational Codeforces Round 57题解的更多相关文章

  1. Codeforces Educational Codeforces Round 57 题解

    传送门 Div 2的比赛,前四题还有那么多人过,应该是SB题,就不讲了. 这场比赛一堆计数题,很舒服.(虽然我没打) E. The Top Scorer 其实这题也不难,不知道为什么这么少人过. 考虑 ...

  2. Educational Codeforces Round 57 (Rated for Div. 2) ABCDEF题解

    题目总链接:https://codeforces.com/contest/1096 A. Find Divisible 题意: 给出l,r,在[l,r]里面找两个数x,y,使得y%x==0,保证有解. ...

  3. Educational Codeforces Round 57 (Rated for Div. 2) D dp

    https://codeforces.com/contest/1096/problem/D 题意 给一个串s,删掉一个字符的代价为a[i],问使得s的子串不含"hard"的最小代价 ...

  4. Educational Codeforces Round 57 (Rated for Div. 2) C 正多边形 + 枚举

    https://codeforces.com/contest/1096/problem/C 题意 问是否存在一正多边形内三点构成的角度数为ang,若存在输出最小边数 题解 三点构成的角是个圆周角,假设 ...

  5. CF Educational Codeforces Round 57划水记

    因为是unrated于是就叫划水记了,而且本场也就用了1h左右. A.B:划水去了,没做 C:大水题,根据初三课本中圆的知识,可以把角度化成弧长,而这是正多边形,所以又可以化成边数,于是假设读入为a, ...

  6. Educational Codeforces Round 19 题解【ABCDE】

    A. k-Factorization 题意:给你一个n,问你这个数能否分割成k个大于1的数的乘积. 题解:因为n的取值范围很小,所以感觉dfs应该不会有很多种可能-- #include<bits ...

  7. Educational Codeforces Round 57 (Rated for Div. 2) 前三个题补题

    感慨 最终就做出来一个题,第二题差一点公式想错了,又是一波掉分,不过我相信我一定能爬上去的 A Find Divisible(思维) 上来就T了,后来直接想到了题解的O(1)解法,直接输出左边界和左边 ...

  8. Educational Codeforces Round 55 题解

    题解 CF1082A [Vasya and Book] 史上最难A题,没有之一 从题意可以看出,翻到目标页只有三种办法 先从\(x\)到\(1\),再从\(1\)到\(y\) 先从\(x\)到\(n\ ...

  9. Codeforces Educational Codeforces Round 54 题解

    题目链接:https://codeforc.es/contest/1076 A. Minimizing the String 题意:给出一个字符串,最多删掉一个字母,输出操作后字典序最小的字符串. 题 ...

随机推荐

  1. 如何加固linux NFS 服务安全的方法

    NFS(Network File System)是 FreeBSD 支持的一种文件系统,它允许网络中的计算机之间通过 TCP/IP 网络共享资源.不正确的配置和使用 NFS,会带来安全问题. 概述 N ...

  2. MySQL-MHA集群部署(binlog复制)

    MHA的理论知识网上有很多教程,这里不会说明:仅推荐博客链接! MHA的理论说明:http://www.ywnds.com/?p=8094 MHA的安装包需要在google上面下载,或者就是csdn上 ...

  3. 简单的HTML5 canvas游戏工作原理

    HTML5已经不是一个新名词.它看上去很cool,有很多feature,大多数人普遍看好它的发展.对于我来说,最感兴趣的是它的canvas标签,可以结合Javascript来绘制游戏画面. 我们可以在 ...

  4. P4303 [AHOI2006]基因匹配 未完成

    题目 luogu 暴力60pts部分 显然如果没有出现次数==5的条件 显然是\(N_{2}\)的求lcs的模板 但是加点条件就完全不同了 思路 这个题短小精悍,不想数据结构那么傻逼无脑 我们考虑一下 ...

  5. SQL Over

    与over函数结合的几个函数 create table #tab(A varchar(), B varchar()) insert into #tab select 'A1', 'B1' union ...

  6. 地宫取宝|2014年蓝桥杯B组题解析第九题-fishers

    地宫取宝 X 国王有一个地宫宝库.是 n x m 个格子的矩阵.每个格子放一件宝贝.每个宝贝贴着价值标签. 地宫的入口在左上角,出口在右下角. 小明被带到地宫的入口,国王要求他只能向右或向下行走. 走 ...

  7. System.ConfigurationManager类用于对配置文件的读取

    http://blog.csdn.net/ligenyingsr/article/details/54095986 System.ConfigurationManager类用于对配置文件的读取.其具有 ...

  8. Java初始化块的作用

    1.使代码更简洁 eg: public class Test { private void init() { System.out.println("初始化状态"); } publ ...

  9. P4 Tutorials Flowlet Switching

    Github链接: Exercise 2: Implementing TCP flowlet switching P4 Tutorials Flowlet Switching 最近P4社区更新了Tut ...

  10. 【Coursera】Security Introduction -Eighth Week(1)

    Security Introduction People With Bad Intent 今天,Bob 向 Alice 发送了一条 "Hello,Allice!" 的信息,他们希望 ...