BZOJ3916: [Baltic2014]friends
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3916
复习一下hash(然后被傻叉错误卡了半天TAT。。。
取出一个字串:h[r]-h[l-1]*power[r-l+1] 然后匹配。。。
注意一下当前需要的是s[i]还是s[i-1],做hash数组时不要写s[i]-'A',写s[i],否则容易被卡
对于这道题,枚举一下断点,注意判重。
对于这种有断点的前面一段+后面一段等于完整一段,要注意前面那一段乘的权。
#include<cstring>
#include<iostream>
#include<cstdio>
#include<algorithm>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define maxn 2000009
#define p 23333
using namespace std;
typedef unsigned long long ll;
char ans[maxn],s[maxn];
ll h[maxn],bin[maxn],last;
int now,n,mid,anspos;
int read(){
int x=,f=; char ch=getchar();
while (!isdigit(ch)){
if (ch=='-') f=-; ch=getchar();
}
while (isdigit(ch)){
x=x*+ch-''; ch=getchar();
}
return x*f;
}
ll get(int l,int r){
return h[r]-h[l-]*bin[r-l+];
}
int judge(int pos){
ll x,y,z;
int flag=;
if (pos<mid){
x=get(,pos-)*bin[mid-pos]+get(pos+,mid);
y=get(mid+,n);
}
else if (pos>mid){
x=get(,mid-);
y=get(mid,pos-)*bin[n-pos]+get(pos+,n);
}
else if (pos==mid){
x=get(,mid-);
y=get(mid+,n);
}
if (x==y){
if (x==last) return ;
last=x;
int top=;
if (pos<=mid) rep(i,mid+,n) ans[++top]=s[i];
else rep(i,,mid-) ans[++top]=s[i];
return ;
}
return ;
}
int main(){
n=read(); if (n%==) {puts("NOT POSSIBLE"); return ;}
scanf("%s",s+);
bin[]=; rep(i,,n) bin[i]=bin[i-]*p;
rep(i,,n) h[i]=h[i-]*p+s[i];
mid=(n/)+;
int cnt=;
rep(i,,n) {
cnt+=judge(i);
if (cnt>) break;
}
if (!cnt) puts("NOT POSSIBLE");
else if (cnt>) puts("NOT UNIQUE");
else puts(ans+);
return ;
}
BZOJ3916: [Baltic2014]friends的更多相关文章
- 【题解】 bzoj3916: [Baltic2014]friends (字符串Hash)
题面戳我 Solution 首先长度为偶数可以直接判掉 然后我们可以枚举删的位置,通过预处理的\(hash\),判断剩余部分是否划分成两个一样的 判重要注意,我们把字符串分为三个部分\(L_l+1+L ...
- 【字符串哈希】bzoj3916 [Baltic2014]friends
枚举断点,哈希判断. #include<cstdio> using namespace std; typedef unsigned long long ull; ull hs,hs1,hs ...
- 【bzoj3916】[Baltic2014]friends 字符串hash
题目描述 有三个好朋友喜欢在一起玩游戏,A君写下一个字符串S,B君将其复制一遍得到T,C君在T的任意位置(包括首尾)插入一个字符得到U.现在你得到了U,请你找出S. 输入 第一行一个数N,表示U的长度 ...
- BZOJ 3916: [Baltic2014]friends( hash )
字符串哈希..然后枚举每一位+各种判断就行了 ----------------------------------------------------------------------------- ...
- BZOJ_3916_[Baltic2014]friends_hash
BZOJ_3916_[Baltic2014]friends_hash 题意: 有三个好朋友喜欢在一起玩游戏,A君写下一个字符串S,B君将其复制一遍得到T,C君在T的任意位置(包括首尾)插入一个字符得到 ...
- 【BZOJ】3916: [Baltic2014]friends
http://www.lydsy.com/JudgeOnline/problem.php?id=3916 #include <bits/stdc++.h> using namespace ...
- BZOJ3919 : [Baltic2014]portals
预处理出每个点上下左右能延伸到的最远点以及到它们的距离的最小值md. 然后spfa,一个点除了可以以1的代价到达四周的点之外,还可以以md+1的代价到达四个方向能到达的最远点. #include< ...
- bzoj3917: [Baltic2014]sequence
Description 序列A由从N开始的连续K个数按顺序构成,现在将A中的每个数只保留某一个数码,记为序列B,给定K和B,求可能的最小的N Input 第一行一个数K,第二行K个数B_i Outp ...
- BZOJ3916: [Baltic2014]friends
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3916 题解:随便hash.刚开始看错题WA了N发.(我连双hash都写了!) 代码: #inc ...
随机推荐
- iOS 面试题、知识点 之一
最近面试,发现这些题个人遇到的几率大一些,与大家分享一下,分三文给大家: 当然Xcode新版本与之前一版本的区别,以及iOS新特性是必要了解的吧. Xcode8 和iOS 10 在之前文章有发过,感兴 ...
- 解决报错:IncompleteElementException: Could not find result map...
今天遇到这样一个报错,记录一下: org.apache.ibatis.builder.IncompleteElementException: Could not find result map com ...
- Jenkins 关闭和重启实现方式.
1.关闭Jenkins 只需要在访问jenkins服务器的网址url地址后加上exit.例如我jenkins的地址http://localhost:8080/,那么我只需要在浏览器地址栏上敲下http ...
- C/C++调用Golang 一
C/C++调用Golang 一 (开发环境: 操作系统: windows 7 32位操作系统 C++: visual studio 2010 Golang:go version go1.9 windo ...
- python (5分钟实现一个游戏的屏蔽敏感字系统,)
import datetime time=datetime.datetime.now() dirty= ['fuck','狗日的','犊子','麻批','仙人板板','R你妈','操你','草你',' ...
- Webpack 2 视频教程 020 - Webpack 2 中的 HMR ( Hot Module Replacement )
原文发表于我的技术博客 这是我免费发布的高质量超清「Webpack 2 视频教程」. Webpack 作为目前前端开发必备的框架,Webpack 发布了 2.0 版本,此视频就是基于 2.0 的版本讲 ...
- 关于recycleview 滑动item变长(item变形)问题
昨天在做项目的时候出现了bug,表现是在滑动的时候,整个item会被拉长了,松手后就回归正常大小了, 出现这个的主要原因是因为你的item布局中最大的那个根布局是 match_parent状态,因此导 ...
- 基于Vue+node.js的个人博客
前言 作为一个年轻的程序员,而且是作为一个未来的前端工程师,怎么能没有一个属于自己的博客呢,于是乎在暑假咸鱼了一个多月后开始了我的博客的编写. 技术栈 前端 vue.js+scss 因为当时没学vu ...
- IDA Pro反编译代码类型转换参考
/* This file contains definitions used by the Hex-Rays decompiler output. It has type definitions an ...
- Python day 6(3) Python 函数式编程1
一:函数式编程概念 函数是Python内建支持的一种封装,我们通过把大段代码拆成函数,通过一层一层的函数调用,就可以把复杂任务分解成简单的任务,这种分解可以称之为面向过程的程序设计.函数就是面向过程的 ...