BZOJ3916: [Baltic2014]friends
题目: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的更多相关文章
- 【hash】Three friends
[来源]:bzoj3916 [参考博客] BZOJ3916: [Baltic2014]friends [ 哈希和哈希表]Three Friends [Baltic2014][BZOJ3916]frie ...
- WC2015 k小割(k短路+暴力+搜索)
首先这道题不是非同一般的恶心,三个数据层次对应三个程序= = PROBLEM:http://uoj.ac/problems解法: 1~2直接暴力枚举边的选择与否+判断就行了 7~14可以发现是一个平面 ...
- BZOJ 3916: [Baltic2014]friends( hash )
字符串哈希..然后枚举每一位+各种判断就行了 ----------------------------------------------------------------------------- ...
- BZOJ_3916_[Baltic2014]friends_hash
BZOJ_3916_[Baltic2014]friends_hash 题意: 有三个好朋友喜欢在一起玩游戏,A君写下一个字符串S,B君将其复制一遍得到T,C君在T的任意位置(包括首尾)插入一个字符得到 ...
- Poweroj:来自学长的善意:ZQ的杀龙之旅(状压BFS)
传送门:https://www.oj.swust.edu.cn/problem/show/2794 来自学长的善意:ZQ的杀龙之旅 Time Limit: 15000 MS Memory Limit: ...
- 【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(然后被傻叉错误卡了半天TAT... 取出一个字串:h[r]-h[l-1 ...
随机推荐
- django邮件
1.邮件变量 (django settings.py) ADMINS = [('JOHN','JOHN@example.com'),('zhang','zhang@example.com')] #设置 ...
- NOSQL快速入门
NoSql是一个很老的概念了,但对自己来说,仍然是一个短板,果断补上. 首先通过几个简单的例子来了解NOSQL在国内的情况(2013年左右的数据,有些过时),比如新浪微博,其就有200多台物理机运行着 ...
- CentOS 7下升级MySQL5.7.23的一个坑
发现CentOS 7下升级MySQL5.7.23的一个坑,以前面升级到MySQL 5.7.23的一个集群为例 在我们环境下打开文件描述符个数的参数open_files_limit在MySQL 5.6. ...
- forof循环
一.语法 1.遍历数组 let myArr=[1,2,3,4,5]; for (let ele of myArr) { console.log(ele); } let myArr=[1,2,3,4,5 ...
- [ 转载 ] Python Web 框架:Django、Flask 与 Tornado 的性能对比
本文的数据涉及到我面试时遇到过的问题,大概一次 http 请求到收到响应需要多少时间.这个问题在实际工作中与框架有比较大的关系,因此特别就框架的性能做了一次分析. 这里使用 2016 年 6 月 9 ...
- listview重新计算高度
将xml中的ListView改用下面的ListViewForScrollView //ScrollView中嵌入ListView,让ListView全显示出来 public class ListVie ...
- 格式化p6spy的输出日志
众所周知, p6spy打印出来的日志是一行很长很长的内容, 很不容易查看, 牛B的p6spy为什么就不能想hibernate那样有format_sql的功能? 竟然没有, 我只好自己动手写一个日志输出 ...
- BZOJ3500 : PA2008 Cliquers
设g[i]表示n=i时的答案,则OEIS上可以找到如下递推式: g[i]=g[i-1]+g[i-2]-g[i-5]-g[i-7]+... 其中符号为++--交替,第i项为f[i],f[1]=1,f[2 ...
- object-c中NSString与int和float的相互转换
1,字符串拼接 NSString *newString = [NSString stringWithFormat:@"%@%@",tempA,tempB]; 2,字符转int in ...
- 喵哈哈村的魔法考试 Round #5 (Div.2) 题解
老规矩 有问题直接联系我:475517977@qq.com A 直接暴力的for一遍,统计连续的有多少个就好了.模拟题. #include<bits/stdc++.h> using nam ...