BZOJ 3916 [Baltic2014]friends

【题解】
暴力枚举添加字符的位置,然后判断去掉这个位置的字符串是否有由两个相同的串拼接而成。本题的n的范围为200W,暴力判断会TLE,所以要使用哈希。
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#define LL long long
#define N 2000010
#define rg register
#define base (107)
using namespace std;
int n,pos,cnt,mid,val;
LL h[N],pow[N];
char s[N],s1[N],s2[N];
map<int,int>u;
inline int read(){
int k=,f=; char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(''<=c&&c<='')k=k*+c-'',c=getchar();
return k*f;
}
inline LL geth(int l,int r){
if(r<l) return ;
return h[r]-h[l-]*pow[r-l+];
}
inline bool check(int x){
int l1=x-,l2=n-x; LL tmp=,tmp2=;
if(x==mid){
tmp=geth(,mid-); tmp2=geth(mid+,n);
}
else{
if(x<mid) tmp=geth(,x-)*pow[mid-x]+geth(x+,mid),tmp2=geth(mid+,n);
else tmp=geth(,mid-),tmp2=geth(mid,x-)*pow[n-x]+geth(x+,n);
}
// printf("%d %lld %lld\n",x,tmp,tmp2);
val=tmp;
return tmp==tmp2;
}
int main(){
n=read(); mid=n/+;
if(!(n&)){puts("NOT POSSIBLE"); return ;}
scanf("%s",s+);
pow[]=;
for(rg int i=;i<=n;i++) h[i]=h[i-]*base+(int)s[i],pow[i]=pow[i-]*base;
// for(rg int i=1;i<=n;i++) printf("%d ",h[i]); puts("");
for(rg int i=;i<=n;i++){
if(check(i)){
if(!u[val]) u[val]=,cnt++,pos=i;
}
if(cnt>) break;
}
if(!cnt) puts("NOT POSSIBLE");
else{
if(cnt>) puts("NOT UNIQUE");
else{
int t=,pointer=;
while(t<=n/){
if(pointer==pos) pointer++;
else printf("%c",s[pointer++]),t++;
}
puts("");
}
}
return ;
}
BZOJ 3916 [Baltic2014]friends的更多相关文章
- BZOJ 3916: [Baltic2014]friends( hash )
字符串哈希..然后枚举每一位+各种判断就行了 ----------------------------------------------------------------------------- ...
- 【BZOJ】3916: [Baltic2014]friends
http://www.lydsy.com/JudgeOnline/problem.php?id=3916 #include <bits/stdc++.h> using namespace ...
- bzoj 3916 暴力哈希
暴力的哈希,注意: 将一个串当作另一个串的前缀,需要乘上p[len],len=后面串的长度 这是自己的代码,拿数据在本地测A掉了,但是bz上wa了??bz换数据了难道?? #include<cs ...
- bzoj 3916: friends 瞎搞
题目: 有三个好朋友喜欢在一起玩游戏,A君写下一个字符串S,B君将其复制一遍得到T,C君在T的任意位置(包括首尾)插入一个字符得到U.现在你得到了U,请你找出S. 题解: 发现字符串的长度一定为奇数. ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- BZOJ刷题指南(转)
基础(65) 巨水无比(4):1214.3816:2B题:1000A+B:2462:输出10个1 模拟/枚举/暴力(15):4063傻子模拟:1968小学生暴力:1218前缀和暴力:3856读英文:4 ...
- BZOJ 2127: happiness [最小割]
2127: happiness Time Limit: 51 Sec Memory Limit: 259 MBSubmit: 1815 Solved: 878[Submit][Status][Di ...
- BZOJ 3275: Number
3275: Number Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 874 Solved: 371[Submit][Status][Discus ...
- BZOJ 2879: [Noi2012]美食节
2879: [Noi2012]美食节 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1834 Solved: 969[Submit][Status] ...
随机推荐
- POJ2127 Greatest Common Increasing Subsequence
POJ2127 给定两个 整数序列,求LCIS(最长公共上升子序列) dp[i][j]表示A的A[1.....i]与B[1.....j]的以B[j]为结尾的LCIS. 转移方程很简单 当A[i]!=B ...
- bzoj3566
3566: [SHOI2014]概率充电器 Time Limit: 40 Sec Memory Limit: 256 MBSubmit: 982 Solved: 422[Submit][Statu ...
- jquery对所有<input type="text"的控件赋值
function resetData() { $("input[type=text]").each( function() { $(this).attr ...
- bzoj 1575: [Usaco2009 Jan]气象牛Baric【dp】
完了不会dp了 设f[i][j]为以i结尾,有j个时的最优值,辅助数组g[i][j]为s选了i和j,i~j中的误差值 转移是f[j][i]=min(f[k][i-1]+g[k][j]) #includ ...
- P4727 [HNOI2009]图的同构记数
传送门 如果我们把选出子图看成选出边,进而看成对边黑白染色,那么就是上一题的弱化版了,直接复制过来然后令\(m=2\)即可 不过直接交上去会T,于是加了几发大力优化 不知为何华丽的被小号抢了rank2 ...
- [Swift通天遁地]一、超级工具-(8)地图视图MKMapView的常用代理方法
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- Eclipse/STS 在线安装阿里java代码规约插件
1.打开Idea的在线安装插件界面,通过“Help”-->“Install New Software...” 进入 2. 在 “Work with” 栏输入插件包的下载地址:https://p3 ...
- Troubleshooting Guide for ORA-12541 TNS: No Listener
Server side checks (not platform specific): 1) Check the result on the server using tnsping to the ...
- jQuery学习笔记(5)-事件与事件对象
一.前言 主要讲解事件的绑定与触发 二.jQuery中添加事件 1.使用bind()方法绑定事件 <input id="btn" type="button" ...
- EasyUI系列学习(八)-ProgressBar(进度条)
一.创建组件 1.class加载 <div class="easyui-progressbar"></div> 2.js加载 <div id=&quo ...