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 ...
随机推荐
- Python函数式编程中map()、reduce()和filter()函数的用法
Python中map().reduce()和filter()三个函数均是应用于序列的内置函数,分别对序列进行遍历.递归计算以及过滤操作.这三个内置函数在实际使用过程中常常和“行内函数”lambda函数 ...
- Python3中的函数 大全
Python 函数 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段. 函数能提高应用的模块性,和代码的重复利用率.Python提供了许多内建函数,比如print().但也可以自己创建 ...
- 随手记录-linux-vim使用
- TeamWork#3,Week5,Scrum Meeting 11.14
根据最近项目出现的问题,我们明确了需要补充的工作,添加了几项任务. 成员 已完成 待完成 彭林江 由于网站信息更新,正在调整爬虫程序结构 更换爬虫结构 郝倩 由于网站信息更新,正在调整爬虫程序结构 更 ...
- 软工实践-Beta 冲刺 (7/7)
队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 1.界面的修改与完善 展示GitHub当日代码/文档签入记 ...
- 第三次作业— C++计算器项目的初始部分
作业题目: C++计算器项目的初始部分 仓库 代码: Scan.h #ifndef SCAN_H #define SCAN_H #include<string> #include<i ...
- (小组)第六次作业:NABCD模型分析。产品Backlog。
NABCD模型分析: NABCD模型分析 1.N——need需求 随着时代的进步,人们生活水平的提高,现在手机的普及率已经非常高了,而且现在的家长很多时候会忙于工作,很少会花时间出来给自己读小学的孩子 ...
- Alpha版本冲刺(六)
目录 组员情况 组员1(组长):胡绪佩 组员2:胡青元 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:翟丹丹 组员7:何家伟 组员8:政演 组员9:黄鸿杰 组员10:刘一好 组员11:何宇恒 展示 ...
- bash简介1
bash脚本语言文件格式 第一行#!/bin/bash :定义bash脚本解释器 注释信息:# 代码注释: 缩进,适度添加空白行 bash中的变量介绍: 局部变量 本地变量 环境变量 位置参数 ...
- python查询mysql以字典返回
# *_*coding:utf-8 *_* import pymysql conn = pymysql.connect(host='192.168.33.10', user='root', passw ...