题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3916

题解:随便hash.刚开始看错题WA了N发.(我连双hash都写了!)

代码:

 #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 2000000+5
#define maxm 200000+5
#define eps 1e-6
#define ll unsigned int
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define for4(i,x) for(int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go)
#define for5(n,m) for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)
#define lch k<<1,l,mid
#define rch k<<1|1,mid+1,r
#define sqr(x) (x)*(x)
#define db double
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,pos;
char s[maxn];
ll h[maxn],p[maxn];
inline ll get(int x,int y){return x>y?:h[y]-h[x-]*p[y-x+];}
ll ans,t1,t2;
inline bool check(int x)
{
if(x>n>>)t1=get(,n>>),t2=(get((n>>)+,x-)*p[n-x]+get(x+,n));
else t1=get(n-(n>>)+,n),t2=(get(,x-)*p[(n>>)-x+]+get(x+,(n>>)+));
return t1==t2;
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();scanf("%s",s+);
if(n%==){printf("NOT POSSIBLE\n");return ;}
p[]=;
for1(i,n)h[i]=h[i-]*+s[i]-'A',p[i]=p[i-]*;
for1(i,n)if(check(i))
{
pos=i;
if(!ans)ans=t1;
else if(t1!=ans){printf("NOT UNIQUE\n");return ;};
}
if(!pos)printf("NOT POSSIBLE\n");
else
{
if(pos>n>>)for1(i,n>>)printf("%c",s[i]);
else for2(i,n-(n>>)+,n)printf("%c",s[i]);
printf("\n");
}
return ;
}

字体为什么忽然变了好鬼畜

BZOJ3916: [Baltic2014]friends的更多相关文章

  1. 【hash】Three friends

    [来源]:bzoj3916 [参考博客] BZOJ3916: [Baltic2014]friends [ 哈希和哈希表]Three Friends [Baltic2014][BZOJ3916]frie ...

  2. WC2015 k小割(k短路+暴力+搜索)

    首先这道题不是非同一般的恶心,三个数据层次对应三个程序= = PROBLEM:http://uoj.ac/problems解法: 1~2直接暴力枚举边的选择与否+判断就行了 7~14可以发现是一个平面 ...

  3. BZOJ 3916: [Baltic2014]friends( hash )

    字符串哈希..然后枚举每一位+各种判断就行了 ----------------------------------------------------------------------------- ...

  4. BZOJ_3916_[Baltic2014]friends_hash

    BZOJ_3916_[Baltic2014]friends_hash 题意: 有三个好朋友喜欢在一起玩游戏,A君写下一个字符串S,B君将其复制一遍得到T,C君在T的任意位置(包括首尾)插入一个字符得到 ...

  5. Poweroj:来自学长的善意:ZQ的杀龙之旅(状压BFS)

    传送门:https://www.oj.swust.edu.cn/problem/show/2794 来自学长的善意:ZQ的杀龙之旅 Time Limit: 15000 MS Memory Limit: ...

  6. 【BZOJ】3916: [Baltic2014]friends

    http://www.lydsy.com/JudgeOnline/problem.php?id=3916 #include <bits/stdc++.h> using namespace ...

  7. BZOJ3919 : [Baltic2014]portals

    预处理出每个点上下左右能延伸到的最远点以及到它们的距离的最小值md. 然后spfa,一个点除了可以以1的代价到达四周的点之外,还可以以md+1的代价到达四个方向能到达的最远点. #include< ...

  8. bzoj3917: [Baltic2014]sequence

    Description  序列A由从N开始的连续K个数按顺序构成,现在将A中的每个数只保留某一个数码,记为序列B,给定K和B,求可能的最小的N Input 第一行一个数K,第二行K个数B_i Outp ...

  9. BZOJ3916: [Baltic2014]friends

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3916 复习一下hash(然后被傻叉错误卡了半天TAT... 取出一个字串:h[r]-h[l-1 ...

随机推荐

  1. Windows下 ffmpeg + labelImg 提取视频帧 得到图片集 并 标注图片 来 构造数据集

    构造数据集的流程 视频文件  >>  ffmpeg处理  >>  图片集  >>  labelImg进行标注  >>  标注好的数据集 准备ffmpeg ...

  2. 021.Zabbix的邮件告警-01

    一 创建Media Administration---->Media types---->Create Media Type   选项 描述 Name 媒介名称,看着起名 Type 选择 ...

  3. VScode 光标乱跳

    JS-CS_html formatter 卸载这个插件 如果没有,或者卸载跟这个类似的,如果还是没有就忽略这个 如果设置过自动保存 在配置上修改为 "files.autoSaveDelay& ...

  4. Future和FutureTask

    上次介绍了Callable实现多线程的方法.现在介绍和Callable搭配的类.上一篇只是简单的用Callable做了一个demo. 一.Future 1.关于callable和runable的区别( ...

  5. MyBatis3与Spring3无缝集成-从iBatis平滑过渡

    从2010开始接触iBatis到现在,一直到现在把iBatis作为数据访问层ORM.为了演示一个Web应用,今天又搭了个SpringMVC应用,由于应用比较简单,Spring版本直接用最新版本3.2. ...

  6. 【bzoj 1076】【SCOI2008】奖励关

    1076: [SCOI2008]奖励关 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1602  Solved: 891[Submit][Status ...

  7. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A. Checking the Calendar 水题

    A. Checking the Calendar 题目连接: http://codeforces.com/contest/724/problem/A Description You are given ...

  8. URAL 1963 Kite 计算几何

    Kite 题目连接: http://acm.hust.edu.cn/vjudge/contest/123332#problem/C Description Vova bought a kite con ...

  9. 使用 IntraWeb (18) - 基本控件之 TIWImage、TIWImageFile、TIWImageList

    TIWImage //用于显示资源中的图片, 设计时通过 Picture 载入图片到资源 TIWImageFile //用于显示给定路径或地址的图片 TIWImageList //它继承于 TImag ...

  10. AE开发中关于 “无法嵌入互操作类型.........请改用适用的接口”问题的解决方法

    最近开始使用VS2010,在引用COM组件的时候,出现了“无法嵌入互操作类型……,请改用适用的接口”的错误提示. 查阅资料,找到解决方案,记录如下: 选中项目中引入的dll,鼠标右键,选择属性,把“嵌 ...