【题目大意】

求一个循环数列的最小表示法。

【思路】

最小表示法的正解:

SAM乱搞,和前面的POJ那道一样。然而MLE了,当作学习一下map的用法^ ^

map的使用方法(来源:

一、map的说明  
  1   头文件 
  #include   <map> 
  
  2   定义 
  map<string,   int>   my_Map; 
  或者是typedef     map<string,   int>   MY_MAP; 
  MY_MAP   my_Map; 
  
  3   插入数据 
  (1)   my_Map["a"]   =   1; 
  (2)   my_Map.insert(map<string,   int>::value_type("b",2)); 
  (3)   my_Map.insert(pair<string,int>("c",3)); 
  (4)   my_Map.insert(make_pair<string,int>("d",4)); 
  
  4   查找数据和修改数据 
  (1)   int   i   =   my_Map["a"]; 
            my_Map["a"]   =   i; 
  (2)   MY_MAP::iterator   my_Itr; 
            my_Itr.find("b"); 
            int   j   =   my_Itr->second; 
            my_Itr->second   =   j; 
  不过注意,键本身是不能被修改的,除非删除。 
  
  5   删除数据 
  (1)   my_Map.erase(my_Itr); 
  (2)   my_Map.erase("c"); 
  还是注意,第一种情况在迭代期间是不能被删除的,道理和foreach时不能删除元素一样。 
  
  6   迭代数据 
  for   (my_Itr=my_Map.begin();   my_Itr!=my_Map.end();   ++my_Itr)   {} 
  
  7   其它方法 
  my_Map.size()               返回元素数目 
  my_Map.empty()       判断是否为空 
  my_Map.clear()           清空所有元素 
  可以直接进行赋值和比较:=,   >,   >=,   <,   <=,   !=   等等

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
const int MAXN=;
int n,k;
struct SAM
{
int tot,last;
int step[MAXN<<],pre[MAXN<<];
map<int,int> next[MAXN<<];
inline int newNode(int cnt)
{
step[++tot]=cnt;
pre[tot]=;
next[tot].clear();
return tot;
} inline void extend(int x)
{
int p=last;
int np=newNode(step[last]+);
map<int,int>::iterator pos;
while (p)
{
pos=next[p].find(x);
if (pos!=next[p].end()) break;
next[p].insert(pair<int,int>(x,np));
p=pre[p];
}
if (!p) pre[np]=;
else
{
int q=pos->second;
if (step[np]==step[p]+) pre[np]=q;
else
{
int nq=newNode(step[p]+);
next[nq]=next[q];
pre[nq]=pre[q];
pre[q]=pre[np]=nq;
while (p)
{
pos=next[p].find(x);
if (pos->second!=q) break;
pos->second=nq;
p=pre[p];
}
}
}
last=np;
} inline void clear()
{
tot=;
last=newNode();
}
}suf;
int a[MAXN]; void init()
{
scanf("%d",&n);
suf.clear();
for (int i=;i<n;i++)
{
scanf("%d",&a[i]);
}
for (int i=;i<n;i++)
suf.extend(a[i]);
for (int i=;i<n;i++)
suf.extend(a[i]);
} void solve()
{
int j=;
for (int i=;i<n;i++)
{
map<int,int>::iterator pos=suf.next[j].begin();
printf("%d",pos->first);
if (i!=n-) printf(" ");
j=pos->second;
}
} int main()
{
init();
solve();
return ;
}

【SAM】BZOJ2882-工艺的更多相关文章

  1. BZOJ2882 工艺【SAM】 最小循环串

    BZOJ2882 工艺 给出一个串,要求其循环同构串中字典序最小的那个 串翻倍建\(SAM\)然后从起点开始贪心的跑\(n\)次即可 当然也能用最小表示法来做 #include<bits/std ...

  2. BZOJ2882:工艺(SAM)

    Description 小敏和小燕是一对好朋友. 他们正在玩一种神奇的游戏,叫Minecraft. 他们现在要做一个由方块构成的长条工艺品.但是方块现在是乱的,而且由于机器的要求,他们只能做到把这个工 ...

  3. [bzoj2882]工艺_后缀数组

    工艺 bzoj-2882 题目大意:题目链接. 注释:略. 想法: 跟bzoj1031差不多啊. 把串倍长后扫$sa$数组. 最后再统计答案即可. Code: #include <iostrea ...

  4. BZOJ2882: 工艺

    题解: 裸的字符串最小表示... 可以戳这里:http://www.cnblogs.com/ACAC/archive/2010/05/23/1742349.html 这里说一下为什么a[i+k]> ...

  5. bzoj2882工艺(最小表示法)

    O(nlogn)的做法十分显然,有三种可以做到O(nlogn)的:1.最容易的想法:把串扩展成两倍,然后跑一遍SA求后缀数组.2.求后缀同样也可以用SAM去求解,用map存一下.3.最暴力的方法:直接 ...

  6. BZOJ2882工艺

    题目描述 小敏和小燕是一对好朋友. 他们正在玩一种神奇的游戏,叫Minecraft. 他们现在要做一个由方块构成的长条工艺品.但是方块现在是乱的,而且由于机器的要求,他们只能做到把这个工艺品最左边的方 ...

  7. bzoj千题计划284:bzoj2882: 工艺

    http://www.lydsy.com/JudgeOnline/problem.php?id=2882 将串S复制一遍变成SS 对SS构建后缀自动机,在上面走标号最小的边len(S)步,即可得最小循 ...

  8. BZOJ2882: 工艺(后缀数组)

    题意 题目链接 Sol 直接把序列复制一遍 后缀数组即可 在前\(N\)个位置中取\(rak\)最小的输出 #include<bits/stdc++.h> using namespace ...

  9. Bzoj2882 工艺 [线性算法]

    后缀自动机题解 -> http://www.cnblogs.com/SilverNebula/p/6420601.html 后缀自动机敲完,看了下排行,wc为什么别人跑得这么快?……是诶,这最小 ...

  10. 【不能继续浪啦】BZ做题记录[7.01~7.06]

    距离上次提交..><居然已经过去一个半月了... 然后再去看看人家RXDoi.. 差距越来越大啦... 最后更新时间:7.06 19:06 [07.03 21:02]夏令营自修课逃逃真爽. ...

随机推荐

  1. RelativeLayout相对布局中属性值

    android:layout_above="@id/xxx"  --将控件置于给定ID控件之上 android:layout_below="@id/xxx"  ...

  2. Perl6 Bailador框架(3):路径匹配

    use v6; use Bailador; =begin pod 注意的是, 当/:one设置时 虽然你有/admin或/about, 但这个/:one不会跟现有的匹配 只跟没有的匹配: 也就是说, ...

  3. ARM中断向量表与响应流程【转】

    转自:http://blog.csdn.net/honour2sword/article/details/40213417 一首先中断向量表定义在哪里?如何加载? 二 中断向量表与中断服务程序 三处理 ...

  4. 448D - Codeforces

    D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes Bizon the C ...

  5. device tree property ---- interrupt-names

    device tree source 的 interrupt-names property 會對應到 pltform_get_irq_byname() 的第二個參數. .dtsi or .dts in ...

  6. python基础===一道小学奥数题的解法

    今早在博客园和大家分享了一道昨晚微博中看到的小学奥数题,后来有朋友给出了答案.然后我尝试用python解答它. 原题是这样的: 数学题:好事好 + 要做好 = 要做好事,求 “好.事.做.要”的值分别 ...

  7. ado中dispose和close的区别,摘自网络

    Close() and Dispose() are basically the same thing on an ADO.NET connection object for providers shi ...

  8. 使用 Visual Studio 部署 .NET Core 应用 ——.Net Core 部署到SUSE Linux Enterprise Server 12 SP2 64 位(GNOME 版本3.20.2)

    SUSE Linux安装 apache 命令:sudo zypper in apache 设置apache 服务可用 命令:sudo systemctl enable apache2.service启 ...

  9. 关于ueditor在Java中文件上传问题,404问题

    问题困扰了两天,部署要求导入到webcontent下,我导入到了整个项目目录下,自己粗心犯错,导致页面访问不到404. 解决了上面的问题,试着进行文件上传,却一直找不到图片: 调出浏览器控制台: 刚开 ...

  10. Django Ajax学习一

    1. 简单的加法 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...