题目: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. mysql varchar 转 decimal

    在我们写代码的实际业务中,有时候实体类用的是String,数据库中自然是VARCHAR类型,但是如果这个实体的属性值放的是数字类型,你查询的时候又需要对它进行排序.sql怎么写呢. 别担心MySQL提 ...

  2. 使用Vmware安装linux且配置终端可以连接虚拟机总结

    首先是下载一个linux镜像,我下载的是:ubuntu-16.04.2-desktop-amd64.iso 1.使用vmware安装linux,都使用默认的配置就行了,最多改一下主机名什么的,密码最好 ...

  3. css 控制文字超出时显示省略号

    不多说,直接看代码吧: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> & ...

  4. 七夕情人节表白-纯JS实现3D心形+图片旋转

    七夕情人节就快到了,这里献上纯js表白神器-心里都是你,预览: 技术点:css-3d.js-随机色.js-transform 1.html: <div class="heart&quo ...

  5. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing 数学

    C. Ray Tracing 题目连接: http://codeforces.com/contest/724/problem/C Description oThere are k sensors lo ...

  6. pat advanced 1139. First Contact (30)

    题目链接 解法暴力 因为有 0000, -0000 这样的数据,所以用字符串处理 同性的时候,遍历好朋友时会直接遍历到对方,这个时候应该continue #include<cstdio> ...

  7. 解决Windows x86网易云音乐不能将音乐下载到SD卡的BUG

    由于我个人最常用的电脑是Surface pro4 256G版本,装了不少生产力空间还挺吃紧的,音乐之类的必然都存单独的SD卡里.用UWP版本的网易云音乐倒是没问题,最近问题来了,UWP版本的网易云音乐 ...

  8. shu_1016 栈

    cid=1079&pid=2">http://202.121.199.212/JudgeOnline/problem.php?cid=1079&pid=2 分析: Ca ...

  9. 如何利用 jQuery 修改 css 中带有 !important 的样式属性?

    使用 jQuery 修改 css 中带有 !important 的样式属性 外部样式为: div.test { width:auto !important; overflow:auto !import ...

  10. 【Go命令教程】3. go install

    命令 go install 用于编译并安装指定的代码包及它们的依赖包.当指定的代码包的依赖包还没有被编译和安装时,该命令会先去处理依赖包.与 go build 命令一样,传给 go install 命 ...