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 ...
随机推荐
- hadoop之定制自己的sort过程
Key排序 1. 继承WritableComparator 在hadoop之Shuffle和Sort中,可以看到mapper的输出文件spill文件需要在内存中排序,并且在输入reducer之前,不同 ...
- Tree - Decision Tree with sklearn source code
After talking about Information theory, now let's come to one of its application - Decision Tree! No ...
- MFC常用操作
目录: 1.文件操作 1.1.获取文件大小 2.路径操作 2.1.创建多级目录 1.文件操作 1.1.获取文件大小 // 获取文件大小 ULONGLONG size = ; // 文件大小 CFile ...
- ubuntu16更新源
http://blog.csdn.net/fengyuzhiren/article/details/54844870
- 如何使用g++编译调用dll的c++代码
本文将有以下4个部分来讲如何使用g++编译调用dll的c++代码. 1.如何调用dll 2.动态链接和静态链接的区别 3.g++的编译参数以及如何编译调用dll的c++代码 4.总结 1.如何调用dl ...
- DataTime日期格式化
C# DateTime日期格式化 在C#中DateTime是一个包含日期.时间的类型,此类型通过ToString()转换为字符串时,可根据传入给Tostring()的参数转换为多种字符串格式. 目录 ...
- 信息安全C散列函数的应用及其安全性2016011992
1:散列函数的具体应用 使用一个散列函数可以很直观的检测出数据在传输时发生的错误. MD5 Hash算法的"数字指纹"特性,使它成为目前应用最广泛的一种文件完整性校验(Checks ...
- TCP系列53—拥塞控制—16、Destination Metrics和Congestion Manager
一.概述 我们之前介绍过rtt.ssthresh等变量,这些变量一般在TCP连接建立的时候有个初始值,然后随着TCP的数据交互逐渐调整到适应对应的网络状态的值.但是如果每次TCP建立连接都依靠默认初始 ...
- cxgrid中,如何根据列名或字段名取得footer值
注意,不是根据index取得footer值cxgrdtbv1.DataController.Summary.FooterSummaryValues[0]; ------解决方案------------ ...
- php错误报告和调试
3. 错误报告和调试 常常犯的一个错误是忘记关闭 PHP 错误和数据库错误报告,这样做是有风险的.在任何一个公开的站点,error_reporting 应该设置为0 ,最多只能设置为 E_ERROR, ...