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)的更多相关文章

  1. 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个由两个字符组成的字符串 ...

  2. 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 ...

  3. Qualification Rounds(Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)+状态压缩)

    题目链接 传送门 题意 现总共有\(n\)个题目\(k\)支参赛队伍,已知每个题目各队伍是否会写,现问你能否从题目中选出一个子序列使得每支队伍最多只会写一半的题目. 思路 对于每个题目我们用二进制压缩 ...

  4. 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 ...

  5. Codeforces Round #438 (Div.1+Div.2) 总结

    本来兴致勃勃的想乘着这一次上紫,于是很早很早的到了机房 但是好像并没有什么用,反而rating-=47 Codeforces Round #438(Div.1+Div.2) 今天就这样匆匆的总结一下, ...

  6. [Codeforces Round #438][Codeforces 868D. Huge Strings]

    题目链接:868D - Huge Strings 题目大意:有\(n\)个字符串,\(m\)次操作,每次操作把两个字符串拼在一起,并询问这个新串的价值.定义一个新串的价值\(k\)为:最大的\(k\) ...

  7. 【Codeforces Round 438 A B C D 四个题】

    题目所在比赛的地址在这里呀 A. Bark to Unlock ·述大意:       输入一个目标串.然后输入n(1<=n<=100)个串,询问是否可以通过这些串收尾相接或者它本身拼出目 ...

  8. Codeforces Round #438 D. Huge Strings

    Description You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations a ...

  9. 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 ...

随机推荐

  1. 页码插入JS脚本

    (function() { var obj = document.createElement("script"); obj.type = "text/javascript ...

  2. 第39次Scrum会议(12/5)【欢迎来怼】

    一.小组信息 队名:欢迎来怼小组成员队长:田继平成员:李圆圆,葛美义,王伟东,姜珊,邵朔,阚博文 小组照片 二.开会信息 时间:2017/12/5 11:35~11:57,总计22min.地点:东北师 ...

  3. 论如何制做一个工程APP的测试内容

    测试一般在软件开发过程中就已经开始进行了,测试越早.发现问题解决他的方案成本就越小.测试按照类型来区分可以划分为:单元测试,集成测试,系统测试.而OCUNIT是XCODE自带的单元测试工具.需要建立新 ...

  4. 构造一个简单的Linux内核的MenuOS

    构造一个简单的Linux内核的MenuOS 20135109 高艺桐 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000 ...

  5. JAVA第一次实验 ——凯撒密码

    课程:Java程序设计 班级:1352 姓名:黄伟业 学号:20135215 成绩:            指导教师:娄嘉鹏  实验日期:2015.4.15 实验密级: 预习程度:  实验时间:19: ...

  6. java程序设计课程实验报告3

    北京电子科技学院(BESTI) 实     验    报     告 课程:java程序设计    班级:1353  姓名:陈都  学号:20135328 成绩:             指导教师:娄 ...

  7. 2018-2019-20172321 《Java软件结构与数据结构》第八周学习总结

    2018-2019-20172321 <Java软件结构与数据结构>第八周学习总结 教材学习内容总结 第12章 优先队列与堆 一.概述 堆 堆的前提就是他首先是一个完全二叉树,其次就是满足 ...

  8. web14 validation.xml配置 登录验证文件配置

    电影网站:www.aikan66.com 项目网站:www.aikan66.com 游戏网站:www.aikan66.com 图片网站:www.aikan66.com 书籍网站:www.aikan66 ...

  9. 求int型数组和最大子数组 续

    之前的博文里已经实现过该程序的构思.编译.运行,本次就不再重复与之相雷同的内容. 题目:与别人借组,借助求int型数组最大和子数组的问题,考虑大数溢出和int取值范围的问题 要求: 调试程序  当子数 ...

  10. OTCL,面向对象的脚本一

    Otcl 简介 面向对象的脚本语言 类变量和类方法 Otcl的基类称为Object(类的名字,不是面向对象中的"对象"),所以的Otcl类都是从Object派送来的. 直接贴代码, ...