题目: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. 条件随机场(crf)及tensorflow代码实例

    对于条件随机场的学习,我觉得应该结合HMM模型一起进行对比学习.首先浏览HMM模型:https://www.cnblogs.com/pinking/p/8531405.html 一.定义 条件随机场( ...

  2. Graph database_neo4j 底层存储结构分析(1)

    1       neo4j 中节点和关系的物理存储模型 1.1  neo4j存储模型 The node records contain only a pointer to their first pr ...

  3. node部署静态页面;node上线静态页面

    node部署静态页面上线 静态页面上线可以采用 nginx, tomcat或者node ,我们这里介绍下node部署静态页面 这里采用最简单的上线方式,我们就不用node + express + ej ...

  4. CentOS 7下KVM支持虚拟化/嵌套虚拟化配置

    开启虚拟化: cat << EOF > /etc/modprobe.d/kvm-nested.conf options kvm-intel nested=1 options kvm- ...

  5. 新浪微博基于MySQL的分布式数据库实践

    提起微博,相信大家都是很了解的.但是有谁知道微博的数据库架构是怎样的呢?在今天举行的2011数据库技术大会上,新浪首席DBA杨海潮为我们详细解读了新浪微博的数据库架构——基于MySQL的分布式数据库实 ...

  6. Asp.net core中的依赖注入

    使用服务 在Asp.net core的Controller中,可以通过如下两种方式获取系统注入的服务: 构造函数 可以直接在构造函数中传入所依赖的服务,这是非常常见的DI注入方式. public Va ...

  7. 怎么发现RAC环境中&#39;library cache pin&#39;等待事件的堵塞者(Blocker)?

    怎么发现RAC环境中的'library cache pin'等待事件的堵塞者(Blocker) 參考自 How to Find the Blocker of the 'library cache pi ...

  8. C#中一种替换switch语句更优雅的写法

    今天在项目中遇到了使用switch语句判断条件,但问题是条件比较多,大概有几十个条件,满屏幕的case判断,是否有更优雅的写法替代switch语句呢? 假设有这样的一个场景:商场经常会根据情况采取不同 ...

  9. Android SDK代理服务器解决国内不能更新下载问题

    原文地址:http://blog.csdn.net/boonya/article/details/38752647 读者须知:本篇文章中最靠谱的是第三种方式,最近有读者反映第三种方式也不行了,下面提供 ...

  10. iOS非ARC内存管理摘要 - 实践型

    关于ios内存管理.在开发过程中,内存管理很重要,我简单说明一下. 1.正确用法 UIView *v = [[UIView alloc] init]; //分配后引用计数为1 [self.view a ...