D. Huge Strings Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
http://codeforces.com/contest/868/problem/D
优化:两个串合并
原有状态+ 第一个串的尾部&第二个串的头部的状态
串变为第一个串的头部&第二个串的尾部
注意:
头尾不能重复
如串A合并串A
这就意味着串的头尾不能有重合,
详见代码
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <time.h>
#include <string>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <ext/rope>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long
#define minv 1e-6
#define inf 1e9
#define pi 3.1415926536
#define E 2.7182818284
const ll mod=1e9+;//
const int maxn=; int w=; int f[maxn][<<(+)]={},add[+];
int len,value;
string str,s,pre[maxn],post[maxn]; void work(int index,string a)
{
int i,j,z;
len=a.length();
for (j=;j<=w;j++)
{
value=;
z=(<<(j-))-;
for (i=;i<len;i++)
{
value=(value<<|(a[i]==''));
if (i>=j-)
{
f[index][value+add[j]]=;
value=value&z;
}
}
}
} int main()
{
int n,q,Q,x,y,i;
add[]=;
for (i=;i<=w+;i++)
add[i]=(<<i)-; scanf("%d",&n);
for (i=;i<=n;i++)
{
cin>>str;
work(i,str);
len=str.size();
if (len<=w)
pre[i]=str;
else
{
pre[i]=str.substr(,w);
if (len>=w+w)
post[i]=str.substr(str.length()-w,w);
else
post[i]=str.substr(str.length()-len+w,len-w);
}
} scanf("%d",&q);
for (Q=n+;Q<=n+q;Q++)
{
scanf("%d%d",&x,&y); for (i=;i<add[w+];i++)
f[Q][i]=f[x][i] | f[y][i]; if (post[x].empty())
str=pre[x];
else if (post[x].length()<w)
str=pre[x].substr(pre[x].length()-(w-post[x].length()),w-post[x].length())+post[x];
else
str=post[x];
str+=pre[y]; work(Q,str); str=pre[x]+post[x]+pre[y]+post[y];
pre[Q]=str.substr(,min(w,(int)str.length()));
str.erase(,min(w,(int)str.length()));
post[Q]=str.substr(str.length()-min(w,(int)str.length()),min(w,(int)str.length())); for (i=;i<add[w+];i++)
if (f[Q][i]==)
break;
printf("%d\n",(int)(log(+i+minv)/log())-);
}
return ;
}
D. Huge Strings Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)的更多相关文章
- Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
A. Bark to Unlock 题目链接:http://codeforces.com/contest/868/problem/A 题目意思:密码是两个字符组成的,现在你有n个由两个字符组成的字符串 ...
- Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combine
最近只想喊666,因为我是真得菜,大晚上到网吧打代码还是很不错的嘛 A. Bark to Unlock time limit per test 2 seconds memory limit per t ...
- Qualification Rounds(Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)+状态压缩)
题目链接 传送门 题意 现总共有\(n\)个题目\(k\)支参赛队伍,已知每个题目各队伍是否会写,现问你能否从题目中选出一个子序列使得每支队伍最多只会写一半的题目. 思路 对于每个题目我们用二进制压缩 ...
- Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined) A,B,C【真的菜·】
8说了 #include<bits/stdc++.h> using namespace std; #define int long long signed main(){ string s ...
- Codeforces Round #438 (Div.1+Div.2) 总结
本来兴致勃勃的想乘着这一次上紫,于是很早很早的到了机房 但是好像并没有什么用,反而rating-=47 Codeforces Round #438(Div.1+Div.2) 今天就这样匆匆的总结一下, ...
- [Codeforces Round #438][Codeforces 868D. Huge Strings]
题目链接:868D - Huge Strings 题目大意:有\(n\)个字符串,\(m\)次操作,每次操作把两个字符串拼在一起,并询问这个新串的价值.定义一个新串的价值\(k\)为:最大的\(k\) ...
- 【Codeforces Round 438 A B C D 四个题】
题目所在比赛的地址在这里呀 A. Bark to Unlock ·述大意: 输入一个目标串.然后输入n(1<=n<=100)个串,询问是否可以通过这些串收尾相接或者它本身拼出目 ...
- Codeforces Round #438 D. Huge Strings
Description You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations a ...
- Codeforces Round #438 B. Race Against Time
Description Have you ever tried to explain to the coordinator, why it is eight hours to the contest ...
随机推荐
- Redis Jedis简介
Redis是一种基于内存类型的数据存储工具 Jedis是一个用java写的Redis数据库操作的客户端,通过Jedis,可以很方便的对redis数据库进行操作.Jedis通过Jedis Pool进行R ...
- JavaScript设计模式-----模板方法模式
模板方法模式是一种只需要使用继承就可以实现的非常简单点的模式. 模板方法模式有两部分组成,第一部分是抽象父类,第二部分是具体的实现子类.通常在抽象父类中封装了子类的算法框架,包括实现 一些公共方法以及 ...
- 使用SSD目标检测c++接口编译问题解决记录
本来SSD做测试的Python接口用起来也是比较方便的,但是如果部署集成的话,肯定要用c++环境,于是动手鼓捣了一下. 编译用的cmake,写的CMakeList.txt,期间碰到一些小问题,简单记录 ...
- linux, configure --prefix 的作用
指定安装路径不指定prefix,则可执行文件默认放在/usr /local/bin,库文件默认放在/usr/local/lib,配置文件默认放在/usr/local/etc.其它的资源文件放在/usr ...
- Linux上安装设置mysql 5.7.24
一,准备 1,先查看Linux是32位还是64位 getconf LONG_BIT 如果返回的是32,那么就是32位 如果返回的是64,那么就是64位 2,如果服务器不能联网,就先去官网下载好压缩包, ...
- No.110_第三次团队会议
前端的易帜 前端在整个软件中有着举足轻重的地位.前端设计一般可以理解为视觉设计,前端开发则是前台代码的实现. 随着科技水平的提高和生产力的提高,人民对于审美的要求逐渐增高.在没有科技壁垒的情况下,是否 ...
- 团队冲刺--Seven
昨天: 司宇航:测试功能版块,优化功能版块. 马佳慧:优化界面 . 王金萱:合并程序. 季方: 合并程序. 今天: 司宇航:优化功能版块. 马佳慧:优化界面 . 王金萱:优化界面. 季方: 完善功 ...
- Git管理分支
管理分支:git branch 直至现在为止,我们的项目版本库一直都是只有一个分支 master.在 git 版本库中创建分支的成本几乎为零,所以,不必吝啬多创建几个分支.下面列举一些常见的分支策略, ...
- SQL SERVER安装(2008)
首先需要下载SQL SERVER2008安装程序:为省的麻烦给出网盘地址自行下载,百度网盘:密码:hslb 1.下载到你所选定文件夹中,我下载在E:\SQL SERVER中 2.选择第一个.exe文件 ...
- Head First Java & 继承