ref

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int nn, n, rnk[60005], tmp[60005], cnt[60005], m=128, p, saa[60005];
char s[15], ss[60005];
void sasort(){
for(int i=0; i<m; i++) cnt[i] = 0;
for(int i=0; i<n; i++) cnt[rnk[i]]++;
for(int i=1; i<m; i++) cnt[i] += cnt[i-1];
for(int i=n-1; i>=0; i--) saa[--cnt[rnk[tmp[i]]]] = tmp[i];
}
void getSuffixArray(){
for(int i=0; i<n; i++){
rnk[i] = ss[i];
tmp[i] = i;
}
sasort();
for(int j=1; p<n; j<<=1){
p = 0;
for(int i=n-j; i<n; i++) tmp[p++] = i;
for(int i=0; i<n; i++)
if(saa[i]>=j)
tmp[p++] = saa[i] - j;
sasort();
p = 1;
swap(rnk, tmp);
rnk[saa[0]] = 0;
for(int i=1; i<n; i++)
if(tmp[saa[i-1]]==tmp[saa[i]] && tmp[saa[i-1]+j]==tmp[saa[i]+j])
rnk[saa[i]] = p - 1;
else
rnk[saa[i]] = p++;
m = p;
}
}
int main(){
cin>>nn;
for(int i=0; i<nn; i++){
scanf("%s", s);
ss[i] = ss[2*nn-i] = s[0];
}
n = nn * 2 + 1;
getSuffixArray();
int A=0, B=nn+1;
while(A+B-nn-1<nn){
if(rnk[A]<rnk[B]) printf("%c", ss[A++]);
else printf("%c", ss[B++]);
if((A+B-nn-1)%80==0) printf("\n");
}
return 0;
}

luogu2870 [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold的更多相关文章

  1. P2870 [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold

    P2870 [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold我比赛的时候A了,luogu上25分,QAQ,又憨又傻的200+代码,我为什么要干电脑干的事情,无语了.如果左边 ...

  2. P2870 [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold 解题报告

    P2870 [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold 题意 给一个字符串,每次可以从两边中的一边取一个字符,要求取出的字符串字典序最小 可以Hash+二分 也可以S ...

  3. 洛谷P2870 - [USACO07DEC]最佳牛线Best Cow Line

    Portal Description 给出一个字符串\(s(|s|\leq3\times10^4)\),每次从\(s\)的开头或结尾取出一个字符接在新字符串\(s'\)的末尾.求字典序最小的\(s'\ ...

  4. [luoguP2870] [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold(后缀数组)

    传送门 数据小的话贪心就行. 可以把这个串翻转再接到后面,再求后缀数组,求出 rank 数组就很简单了. ——代码 #include <cstdio> #include <iostr ...

  5. 洛谷P2870 [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold

    思路大概和其他的题解一样: 从当前字符串最前面,最后面选一个字典序较小的然后拉到一个新的字符串序列中,如果相同就一直往中间扫描直到发现不同为止(一个字符如果被选中之后那么就不可以再次选择了),所以我们 ...

  6. POJ3623 Best Cow Line, Gold 【后缀数组】

    最好的牛线,金 时间限制: 5000MS   内存限制: 65536K 提交总数: 5917   接受: 2048 描述 FJ即将把他的ñ(1≤ ñ ≤30,000)头牛竞争一年一度的"年度 ...

  7. POJ3623:Best Cow Line, Gold(后缀数组)

    Description FJ is about to take his N (1 ≤ N ≤ 30,000) cows to the annual"Farmer of the Year&qu ...

  8. HDU 3623 Best Cow Line, Gold(模拟,注意思路,简单)

    题目 POJ 3617 和 这道题题目一样,只是范围稍稍再小一点. //模拟试试 #include<stdio.h> #include<string.h> #include&l ...

  9. 【POJ 3623】 Best Cow Line, Gold (后缀数组)

    [题意] [分析] 后缀数组水题,嗯,不认真看输出像我一样就会被坑.. #include<cstdio> #include<cstdlib> #include<cstri ...

随机推荐

  1. 创作了一个xml的替代格式

    xml格式: <?xml version="1.0" encoding="GB2312"?> <Relations> <Relat ...

  2. Piwik-2.16.1 (OpenLogic CentOS7.2)

    平台: CentOS 类型: 虚拟机镜像 软件包: centos7.2 piwik devops log analysis monitoring open-source 服务优惠价: 按服务商许可协议 ...

  3. vuejs里面v-if,v-show和v-for

    <div id='root'> <div v-if='show'>helle world</div> <button @click='handleClick' ...

  4. python __getattr__ __setattr__

    class Rectangle: def __init__(self): self.width = 0 self.height = 0 def __setattr__(self, key, value ...

  5. 1.redis 安装

    1.https://redis.io/download. 2. $ wget http://download.redis.io/releases/redis-3.2.9.tar.gz $ .tar.g ...

  6. thymeleaf获取当前时间并格式化输出

    有时候会需要在模板中直接打印时间的需求,如果输出一个时间还需要在java类中去获取model的话,那未免也太麻烦了,以下为thymeleaf在模板中直接获取时间戳并格式化输的代码 获取时间戳 < ...

  7. java编程基础——二叉树的镜像

    题目描述 操作给定的二叉树,将其变换为源二叉树的镜像. 题目代码 /** * @program: JavaCode * @description: 操作给定的二叉树,将其变换为源二叉树的镜像. * 二 ...

  8. react属性校验

    https://reactjs.org/docs/typechecking-with-proptypes.html 1.安装:cnpm i prop-types -S import PropTypes ...

  9. 牛客小白月赛1 G あなたの蛙は旅⽴っています【图存储】【DP】

    题目链接:https://www.nowcoder.com/acm/contest/85/G 思路: DP 空间可以优化成一维的, 用一维数组的 0 号单元保存左斜对角的值即可. 存图这里真不好理解 ...

  10. linux内核--定时器API

    /**<linux/timer.h> 定时器结构体 struct timer_list { ........ unsigned long expires; --内核希望定时器执行的jiff ...