Codeforces 868 D Huge String
来源:互联网 发布:sql 2008 sa 无法登陆 编辑:程序博客网 时间:2024/06/06 06:30
题目地址
题意:给你n个字符串(0和1),然后给你m次操作,每一次操作都是把两个字符串拼接起来得到的一个新的字符串放入数组n+i的位置上,然后判断出这个新的字符串包含的最长0和1的全排列(全部)。
思路:看了别人的说法才知道可以直接暴力枚举,每次把字符串拼接起来,放入最后一个位置,再对这个字符串直接通过位运算来生成长度为K的全排列,看这个子字符串是不是拼接字符串的子串。然后把最大的k与拼接的两个字符串的最大K进行比较,取最大的放入数组,准备下一次查询。
其实最重要的是为什么可以用暴力枚举,因为每个字符串的长度最多为100,在最理想的条件下只能有6的全部全排列字符串,然而我们进行拼接是不会增加K的,所以我们就可以使用暴力的方法。但是为了防止
MLE我们对于拼接以后字符串大于1000的就取他的前缀和后缀各500个字符就好了。
#include <iostream>#include <cstring>#include <string>#include <queue>#include <vector>#include <map>#include <set>#include <cmath>#include <cstdio>#include <algorithm>#include <iomanip>#define N 1010#define M 2000010//双倍#define LL __int64#define inf 0x3f3f3f3f#define lson l,mid,ans<<1#define rson mid+1,r,ans<<1|1#define getMid (l+r)>>1#define movel ans<<1#define mover ans<<1|1using namespace std;const LL mod = 1000000007;const double eps = 0.001;string str[N];int num[N];int solve(int x) { for (int i = 1; i <= 10; i++) { for (int j = 0; j < (i << i); j++){//遍历每一个串 string newstr = ""; for (int k = 0; k <= i - 1; k++) {//把数字转为字符串 if (j&(1 << k)) { newstr += '1'; } else { newstr += '0'; } } if (str[x].find(newstr)==str[x].npos) return i - 1; } }}int main() { cin.sync_with_stdio(false); int n, m; int a, b; while (cin >> n) { memset(num, -1, sizeof(num)); for (int i = 1; i <= n; i++) { cin >> str[i]; } cin >> m; for (int i = 1; i <= m; i++) { cin >> a >> b; if (num[a] == -1) { solve(a); } if (num[b] == -1) { solve(b); } str[n + i] = str[a] + str[b]; if(str[n+i].length()>1000) str[n + i] = str[n + i].substr(0, 500) + str[n + i].substr(str[n + i].length() - 500, 500); num[n + i] = max(max(num[a], num[b]), solve(n + i)); cout << num[n + i] << endl; } } return 0;}
阅读全文
0 0
- Codeforces 868 D Huge String
- Codeforces 868 D. Huge Strings (二分+随机+SAM)
- Codeforces 868 D. Huge Strings 字符串思维乱搞
- Codeforces 868D (Codeforces Round #438 D) Huge Strings 分治+哈希
- Codeforces 168D Wizards and Huge Prize
- 【Codeforces 682D】【String】
- HDU 4693 Huge String
- Codeforces Round #438 (Div. 1 + Div. 2 combined) D. Huge Strings
- 【codeforces 779D】String Game
- codeforces 779 D. String Game
- codeforces 895D String Mark
- CF2017.10.5 D. Huge Strings
- hdu4693 Huge String,高精度,dp
- codeforces 123 D String(后缀自动机 SAM)
- Codeforces 196 D. The Next Good String
- codeforces 709 D Recover the String (构造)
- Codeforces 779D String Game 二分
- codeforces 778D. String Game (二分搜索)
- 浅谈A*算法
- 【Java】の基础——注解
- CF875F 图论(好题啊)
- [Oracle 11g r2(11.2.0.4.0)]案例分析8-本地节点hang 住导致的集群重新配置
- 面试问题总结
- Codeforces 868 D Huge String
- 树状数组模板
- 如何评定产品需求的优先级
- 每天一个linux命令-文件(1)-df
- 10个国内外jQuery的CDN性能大比拼
- Rhyme/ Java 设计模式之类与类之间的关系—依赖、关联(聚合与组合)、继承、实现
- 看了这七条你会成为更好的设计
- 1.5人与计算机之间用什么语言交流?如何实现更有效的人机交流?
- SqlServer 连接字串不使用数据库名 实现跨库查询