这场比赛没有打,后来和同学们一起开了场镜像打……

B是SB题结果WA了5发……

C是SB题结果差5min调出……虽然中间有个老师讲题吃掉了1h

D是比较神仙的题(2200),但是做出来了?算是比较超常发挥了。(平常能做出的题中最难的就是2200了)

E是2800,F是2900,zblzbl……

这次发挥还是不错的,写一篇题解吧。


A

首先发现在一个圆上删掉 $m$ 个点,段数的上界为 $m$。($0$ 除外,所以要特判 $0$)

然后剩下了 $n-m$ 个点。答案就是 $\min(m,n-m)$。

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>'') f|=ch=='-',ch=getchar();
while(ch>='' && ch<='') x=x*+ch-'',ch=getchar();
return f?-x:x;
}
int main(){
int n=read(),m=read();
if(!m) printf("%d\n",);
else printf("%d\n",min(m,n-m));
}

B1/B2

枚举 $k$ 看看可不可行。

与数出现次数有关,给数开个桶。

对于B1,直接大暴力讨论即可。

对于B2,对桶再开个桶,就能优化暴力。

时间复杂度 $O(n)$。(细节太多了,就WA了5发……)

#include<bits/stdc++.h>
using namespace std;
const int maxn=,mod=;
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>'') f|=ch=='-',ch=getchar();
while(ch>='' && ch<='') x=x*+ch-'',ch=getchar();
return f?-x:x;
}
int n,c1[maxn],c2[maxn],cnt,ans;
int main(){
n=read();
FOR(i,,n){
int w=read();
c2[c1[w]]--;
if(!c2[c1[w]]) cnt--;
c1[w]++;
c2[c1[w]]++;
if(c2[c1[w]]==) cnt++;
if(cnt== && (c1[w]== || c2[c1[w]]==) || (cnt== && (c2[c1[w]+]== || c2[c1[w]]== && c2[c1[w]-] || c2[]==))) ans=max(ans,i);
}
printf("%d\n",ans);
}

C1/C2

C1大暴力,没啥好说的。

C2反向考虑,斜率相同的直线对数。

记得去重。记得特判没有斜率($x$ 坐标相同)。

时间复杂度 $O(n^2\log n)$。(实现够好可以 $O(n^2)$?)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=;
const double eps=1e-;
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>'') f|=ch=='-',ch=getchar();
while(ch>='' && ch<='') x=x*+ch-'',ch=getchar();
return f?-x:x;
}
struct line{
double k,b;
bool operator<(const line &l)const{
if(fabs(k-l.k)>eps) return k<l.k;
return b<l.b;
}
bool operator==(const line &l)const{
return fabs(k-l.k)<eps && fabs(b-l.b)<eps;
}
}l[maxn*maxn];
int n,x[maxn],y[maxn],m,cnt[],ccc;
ll ans;
int main(){
n=read();
FOR(i,,n) x[i]=read(),y[i]=read();
FOR(i,,n) FOR(j,i+,n){
if(x[i]==x[j]){
cnt[x[i]+]++;
if(cnt[x[i]+]==) ccc++;
continue;
}
double k=1.0*(y[i]-y[j])/(x[i]-x[j]);
l[++m]=(line){k,y[i]-k*x[i]};
}
sort(l+,l+m+);
m=unique(l+,l+m+)-l-;
ans=1ll*m*(m-)/+1ll*m*ccc;
for(int ll=,rr;ll<=m;ll=rr+){
rr=ll;
while(rr<=m && fabs(l[ll].k-l[rr].k)<eps) rr++;
rr--;
ans-=1ll*(rr-ll+)*(rr-ll)/;
}
cout<<ans<<endl;
}

D

考虑DP,$f[i][j][k]$ 表示 $c$ 的前 $i$ 个字符替换完了,$s$ 能匹配到前缀 $j$,$t$ 能匹配到前缀 $k$ 的最大值。

初始,$f[0][0][0]=0$,其他为 -INF。

转移,可以从 $f[i][j][k]$ 到 $f[i+1][j'][k'](0/+1/-1)$。后面的 $0/+1/-1$ 就要判断 $s$ 和 $t$ 是否可以匹配。

答案为 $\max(f[|c|][j][k])$。此时时间复杂度为 $O(|c||s|^3|t|^3|A|)$,优秀一点可以做到 $O(|c||s||t||A|+(|s|^3+|t|^3)|A|)$。(预处理 $to_s[i][c]$ 表示从 $s$ 的第 $i$ 个字符扩展一个 $c$ 最远能是哪个前缀,$t$ 类似)

此时已经可以通过本题,然而我SB没想到预处理 $to_s$,所以用了 KMP 优化找 $j'$ 和 $k'$。

时间复杂度 $O(|c||s||t||A|)$。

似乎可以用AC自动机或者讨论 $j$ 和 $k$ 的大小关系继续优化。

#include<bits/stdc++.h>
using namespace std;
const int maxn=,mod=;
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>'') f|=ch=='-',ch=getchar();
while(ch>='' && ch<='') x=x*+ch-'',ch=getchar();
return f?-x:x;
}
int l,n,m,f[maxn][][],nxts[],nxtt[],ans=-1e9;
char c[maxn],s[],t[];
void get_nxt(char s[],int l,int nxt[]){
int j=;
FOR(i,,l){
while(j && s[i]!=s[j+]) j=nxt[j];
if(s[i]==s[j+]) j++;
nxt[i]=j;
}
}
inline void chkmax(int &x,int y){if(y>x) x=y;}
void use(int i,int j,int k,char x){
int jj=j,kk=k;
while(jj && x!=s[jj+]) jj=nxts[jj];
if(x==s[jj+]) jj++;
while(kk && x!=t[kk+]) kk=nxtt[kk];
if(x==t[kk+]) kk++;
if(jj==n){
if(kk==m) chkmax(f[i+][nxts[n]][nxtt[m]],f[i][j][k]);
else chkmax(f[i+][nxts[n]][kk],f[i][j][k]+);
}
else{
if(kk==m) chkmax(f[i+][jj][nxtt[m]],f[i][j][k]-);
else chkmax(f[i+][jj][kk],f[i][j][k]);
}
}
int main(){
scanf("%s%s%s",c+,s+,t+);
l=strlen(c+);n=strlen(s+);m=strlen(t+);
get_nxt(s,n,nxts);
get_nxt(t,m,nxtt);
MEM(f,~0x3f);
f[][][]=;
FOR(i,,l-) FOR(j,,n) FOR(k,,m){
if(c[i+]!='*') use(i,j,k,c[i+]);
else FOR(x,'a','z') use(i,j,k,x);
}
FOR(j,,n) FOR(k,,m) ans=max(ans,f[l][j][k]);
printf("%d\n",ans);
}

E/F

会了再来填吧。

Codeforces Round 558(Div 2)题解的更多相关文章

  1. Codeforces Round #558 (Div. 2)

    目录 Codeforces Round #558 (Div. 2) 题解 A Eating Soup B Cat Party C Power Transmission D Mysterious Cod ...

  2. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  3. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  4. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  5. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  6. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  7. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

  8. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

  9. Codeforces Round #160 (Div. 1) 题解【ABCD】

    Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...

随机推荐

  1. R语言构建蛋白质网络并实现GN算法

    目录 R语言构建蛋白质网络并实现GN算法 1.蛋白质网络的构建 2.生物网络的模块发现方法 3.模块发现方法实现和图形展示 4.附录:igraph中常用函数 参考链接 R语言构建蛋白质网络并实现GN算 ...

  2. WPF 精修篇 BackgroundWorker

    原文:WPF 精修篇 BackgroundWorker 效果 <Grid> <Grid.RowDefinitions> <RowDefinition Height=&qu ...

  3. 解决Web部署 svg/woff/woff2字体 404

    1.打开服务器IIS管理器,找到MIME类型 2.添加类型 文件扩展名      MIME类型 .svg             image/svg+xml.woff            appli ...

  4. 05 .NET CORE 2.2 使用OCELOT -- NLog

    加入NLog 按照官网的文档 https://github.com/NLog/NLog/wiki/Getting-started-with-ASP.NET-Core-2 一步一步操作下来,即可设置好. ...

  5. C# HttpWebRequest和WebClient的区别 通过WebClient/HttpWebRequest实现http的post/get方法

    一 HttpWebReques1,HttpWebRequest是个抽象类,所以无法new的,需要调用HttpWebRequest.Create();2,其Method指定了请求类型,这里用的GET,还 ...

  6. linux系统shell基础知识入门

    什么是shell shell就是我们常说的命令行程序,它是一个作为用户与Linux系统间接口的程序,它允许用户向操作系统输入要执行的命令.在Linux中安装多个shell是可行的,一般系统有默认的sh ...

  7. SQL Server强制释放内存

    --强制释放内存 CREATE procedure [dbo].ClearMemory as begin --清除所有缓存 DBCC DROPCLEANBUFFERS --打开高级配置 EXEC (' ...

  8. css flex兼容性

    我测试了一下css flex的兼容性 已经可以兼容到IE10了呀 为啥MDN上面的IE兼容性还是兼容到IE11 有点更新不及时的感觉

  9. leetcode 学习心得 (4)

    645. Set Mismatch The set S originally contains numbers from 1 to n. But unfortunately, due to the d ...

  10. 微信小程序-获取当前位置和城市名

    微信小程序-获取当前城市位置 1, 获取当前地理位置,首先要拿到用户的授权wx.openSetting: 2,微信的getLocation接口,获取当前用户的地理位置(微信返回的是经纬度,速度等参数) ...