BUAA Summer Practice 2017 #1 字符串专场
https://vjudge.net/contest/262753#overview
C - Regular Number HDU - 5972
bitset temp, temp[i]=1表示 此前i个位置都能完全匹配,&=bt[x-'0']来递推
int n,a[1111][12];
char s[5000050];
int main()
{
while(~scanf("%d",&n))
{
bitset<1000> bt[11];
re(i,0,9)bt[i].reset();
re(i,1,n)
{
int x;inin(x);
re(j,1,x)
{
int y;inin(y);
bt[y][i-1]=1;
}
}
strin(s+1);
int len=strlen(s+1);
while(s[len]<'0'||s[len]>'9')len--;
bitset<1000> temp;
temp.reset();
re(i,1,len)
{
temp<<=1;
temp[0]=1;
temp&=bt[s[i]-'0'];
if(temp[n-1]==1)
{
fwrite(s+i-n+1,sizeof(s[0]),n,stdout);
puts("");
}
}
}
return 0;
}
A - Password Suspects UVALive - 4126
AC自动机上DP,ans[x][y][s]表示当前在x结点,已经用了y个字符,已经含有了s集合中的子串,之后还有多少种方法。
调了半天发现没考虑输入相同的子串。
int ch[111][27],pre[111],tag[111],ed;
int n,m;
void add(char *s,int x)
{
int temp=0;
while(*s)
{
int c=(*s)-'a';
if(!ch[temp][c])ch[temp][c]=++ed;
temp=ch[temp][c];
s++;
}
tag[temp]|=(1<<x);
}
queue<int> h;
void getpre()
{
re(i,0,25)if(ch[0][i])h.push(ch[0][i]);
while(!h.empty())
{
int x=h.front();h.pop();
tag[x]|=tag[pre[x]];
re(i,0,25)
{
if(!ch[x][i])
{
ch[x][i]=ch[pre[x]][i];
continue;
}
int vv=ch[x][i];
int k=pre[x];
pre[vv]=ch[k][i];
h.push(vv);
}
}
}
bool bo[105][28][1028];
LL ans[105][28][1028];
LL dfs(int x,int y,int s)
{
if(bo[x][y][s])return ans[x][y][s];
bo[x][y][s]=1;
if(y==n)return ans[x][y][s]=(s==(1<<m)-1)?1:0;
LL &aa=ans[x][y][s];
aa=0;
re(i,0,25)aa+=dfs(ch[x][i],y+1,s|tag[ch[x][i]]);
return aa;
}
char ss[332];
void out(int x,int y,int s)
{
if(y==n)
{
if(s==(1<<m)-1)ss[n]=0,puts(ss);
return ;
}
re(i,0,25)
{
int vv=ch[x][i];
if(bo[vv][y+1][s|tag[vv]]&&ans[vv][y+1][s|tag[vv]])
ss[y]=i+'a',out(vv,y+1,s|tag[vv]);
}
}
int tt;
char s[122];
int main()
{
// freopen("a.in","r",stdin);
while(~scanf("%d%d",&n,&m))
{
tt++;
if(!n)return 0;
ed=0;
Clear(pre,0);
Clear(ans,0);
Clear(bo,0);
Clear(ch,0);
Clear(tag,0);
re(i,1,m)strin(s+1),add(s+1,i-1);
getpre();
LL ans=dfs(0,0,0);
printf("Case %d: %lld suspects\n",tt,ans);
if(ans<=42)out(0,0,0);
}
return 0;
}
L - The Problem to Slow Down You UVALive - 7041
求两个字符串相同回文子串数目
构建回文树然后dfs相同结点(路径)
struct st
{
int ch[200010][27],sum[200010],len[200010],pre[200020],ed;
char s[200010];
int getpre(int x,int y)
{
while(s[y]!=s[y-len[x]-1])x=pre[x];
return x;
}
void Main()
{
ed=1;
Clear(ch[0],0),Clear(ch[1],0);
len[0]=0,len[1]=-1;
pre[0]=1;
strin(s+1);
int l=strlen(s+1),temp=0;
s[0]=-1;
re(i,1,l)
{
int now=getpre(temp,i);
if(!ch[now][s[i]-'a'])
{
int k=++ed;
sum[k]=0;
Clear(ch[k],0);
len[k]=len[now]+2;
pre[k]=ch[getpre(pre[now],i)][s[i]-'a'];
ch[now][s[i]-'a']=k;
}
sum[temp=ch[now][s[i]-'a']]++;
}
rre(i,ed,0)sum[pre[i]]+=sum[i];
}
}t[2];
LL ans;
void dfs(int t0,int t1)
{
if(t[0].len[t0]>0)ans+=1LL*t[0].sum[t0]*t[1].sum[t1];
re(i,0,25)if(t[0].ch[t0][i]&&t[1].ch[t1][i])dfs(t[0].ch[t0][i],t[1].ch[t1][i]);
}
int T;
int main()
{
inin(T);int tt=T;
while(T--)
{
ans=0;
t[0].Main();
t[1].Main();
dfs(0,0);
dfs(1,1);
printf("Case #%d: %lld\n",tt-T,ans);
}
return 0;
}
K - Om Nom and Necklace CodeForces - 526D
可以证明i-pre[i]是最短的循环节长度(B+A),然后判断是否能把i拆成k个循环节+一个长度小于循环节的串,或者直接拆成k+1个循环节,前者用二分判,后者直接判整除。
char a[1000010];
int pre[1000010];
void getpre(char *s)
{
int k=0;int n=strlen(s+1);
re(i,2,n)
{
while(k&&s[i]!=s[k+1])k=pre[k];
if(s[i]==s[k+1])k++;
pre[i]=k;
}
}
int n,k;
int main()
{
inin(n),inin(k);
strin(a+1);
getpre(a);
int len=strlen(a+1);
re(i,1,len)
{
int x=i-pre[i];
if(i%x==0&&(i/x)%(k+1)==0)putchar('1');
else
{
int l=1,r=i/x,mid;
while(l<r)
{
mid=(l+r)>>1;
if(i/(mid*x)>k)l=mid+1;
else r=mid;
}
if(i/(l*x)==k)putchar('1');
else putchar('0');
}
}
return 0;
}
BUAA Summer Practice 2017 #1 字符串专场的更多相关文章
- s14 第5天 时间模块 随机模块 String模块 shutil模块(文件操作) 文件压缩(zipfile和tarfile)shelve模块 XML模块 ConfigParser配置文件操作模块 hashlib散列模块 Subprocess模块(调用shell) logging模块 正则表达式模块 r字符串和转译
时间模块 time datatime time.clock(2.7) time.process_time(3.3) 测量处理器运算时间,不包括sleep时间 time.altzone 返回与UTC时间 ...
- Day5模块-time和datetime模块
模块是封装一段代码来实现某种功能. 分为三类: 1.自定义模块 2.标准库,内置模块 3.开源模块 -------------------------------------------------- ...
- 自学Python5.4-内置模块(2)
内置模块(2) 7. xml8.conf9.requests10.logging11.paramiko12.time & datetime 时间相关的操作,时间主要分三种表示方式: 时间戳 ...
- DAX和Power BI中的参考日期表
本文使用Power BI模板描述DAX中的引用Date表,可以在Analysis Services模型中使用相同的技术.在Dax Date Template页面下载最新版本的模板. 为什么引用Date ...
- Python之旅Day6 模块应用
time datetime random os sys shutil pickle json shelv xml configparser hashlib subprocess logging re ...
- 算法(第四版)C# 习题题解——1.2
写在前面 整个项目都托管在了 Github 上:https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp 这一节内容可能会用到的库文件有 ...
- 自学Python6.4-内置模块(2)
自学Python之路-Python基础+模块+面向对象自学Python之路-Python网络编程自学Python之路-Python并发编程+数据库+前端自学Python之路-django 自学Pyth ...
- JAVA基础——时间Date类型转换
在java中有六大时间类,分别是: 1.java.util包下的Date类, 2.java.sql包下的Date类, 3.java.text包下的DateFormat类,(抽象类) 4.java.te ...
- 模块讲解----time与date time(时间模块)
time和datetime 在python中,通常有一下几种方式来表示时间:1.时间戳:2.格式化时间字符串:3.元祖(struct_time):其中元祖(struct_time分为九个元素) UTC ...
随机推荐
- LeetCode第二题
题目描述: You are given two non-empty linked lists representing two non-negative integers. The digits ar ...
- 壁虎书3 Classification
MNIST fetch_openml returns the unsorted MNIST dataset, whereas fetch_mldata() returned the dataset s ...
- Differenciate or distinguish between outlook attachment and embedded image/signature using property accessor in C#.NET
These days, outlook emails are composed in three formats; plain text, html and rtf (rich text format ...
- mysql添加字段
使用事务给表添加字段 #添加字段说明 USE test;/*库名*/ DROP PROCEDURE IF EXISTS schema_change; DELIMITER // CREATE PROCE ...
- nginx上通过ssl证书将http转发为https
环境:阿里云linux,ngnix 1.16.0 ,ssl证书,XXXX.jar 0.自行在阿里云上下载免费的ssl证书.里面有2个文件.key和pem后面要用到. 1.首先将项目在linux上跑起来 ...
- MarkDown语言
参考: 参考:https://typora.io/ 参考:https://caret.io/ Markdown是一种轻量级标记语言,创始人为約翰·格魯伯(英语:John Gruber). 它允许人们“ ...
- [dev][ipsec] netlink是什么
介绍: https://www.linuxjournal.com/article/7356 大纲: man手册 http://man7.org/linux/man-pages/man7/netlink ...
- 截取字段split
172.0.0.1String[] splitAddress=qip.split("\\.");//--172001 String ip=splitAddress[0]+" ...
- 安装VC6.0安装步骤及心得体会
一.安装步骤: 1.打开网站https://pan.baidu.com/s/nxee/AD ,输入提取密码:wdhk. 2.登录微信账号,将软件下载到D盘. 3.鼠标右键点击VC6.0快捷方式,选择“ ...
- Custom Window
public class CustomWnd : System.Windows.Window { static CustomWnd() { DefaultStyleKeyProperty.Overri ...