link:http://acm.hdu.edu.cn/showproblem.php?pid=4691

暴力,数据明显太水了吧,n=10^5, O(n^2)的复杂度哎喂。想让大家暴力写直接让n=1000不就得了么,这算什么。

 #include <iostream>
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
 #include <cmath>
 #include <cctype>
 #include <algorithm>
 #include <queue>
 #include <deque>
 #include <queue>
 #include <list>
 #include <map>
 #include <set>
 #include <vector>
 #include <utility>
 #include <functional>
 #include <fstream>
 #include <iomanip>
 #include <sstream>
 #include <numeric>
 #include <cassert>
 #include <ctime>
 #include <iterator>
 const int INF = 0x3f3f3f3f;
 ][] = {{-,},{,},{,-},{,},{-,-},{-,},{,-},{,}};
 using namespace std;
 ], b[];
 //#define LL long long
 #define LL __int64
 int main(void)
 {
     #ifndef ONLINE_JUDGE
     freopen("in.txt", "r", stdin );
     #endif // ONLINE_JUDGE
     while (~scanf("%s", a))
     {
         int n; scanf("%d", &n);
         ;
         LL ans = , bns = ;
         scanf("%d%d", &pl, &pr);
         bns += (pr - pl + );
         ans += (pr - pl +  + );
         ; so < n-; ++so)
         {
             scanf("%d%d", &l, &r);
             bns += (r - l + );
             tmp = ; int pos = pl, i;
             for (i = l; i < r && pos < pr; ++i)
             {
                 if (a[i] == a[pos]) tmp++, pos++;
                 else break;
             }
             sprintf(b, "%d", tmp);
             ans += strlen(b);
             ans += (r-l-(i-l)); ans += ;
             pl =l, pr = r;
         }
 //        printf("%lld %lld\n", bns, ans);
 //        printf("bns = %lld\n",bns);
 //        printf("ans = %lld\n",ans);
 //        printf("%lld %lld\n", bns, ans);
         cout << bns << " " << ans << endl;
     }
     ;
 }

标准做法据说是后缀数组+RMQ,留坑,今天研究一下再说。

不过还是有个问题,为什么上面这个程序里面62行是对的,61行输出就不对呢?明明是一样的啊,还好,我用59,60两行检验了一下,没浪费太多时间,只是现在还是不知道为什么,难道是输出格式错了??

o(╯□╰)o

走吧,小胖!

hdu4691 Front compression ——暴力 || 后缀数组的更多相关文章

  1. hdu 4691 Front compression (后缀数组)

    hdu 4691 Front compression 题意:很简单的,就是给一个字符串,然后给出n个区间,输出两个ans,一个是所有区间的长度和,另一个是区间i跟区间i-1的最长公共前缀的长度的数值的 ...

  2. HDU 4691 Front compression(后缀数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4691 题意:给出Input,求出Compressed output.输出各用多少字节. 思路:求后缀数 ...

  3. hdu4691 Front compression(后缀数组)

    Front compression Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others) ...

  4. HDU-4691 Front compression 后缀数组

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4691 后缀数组模板题,求出Height数组后,对Height做RMQ,然后直接统计就可以了... // ...

  5. BZOJ_2754__[SCOI2012]_喵星球上的点名_(暴力+后缀数组)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=2754 给出n个姓名串和m个点名串.求每个点名串在多少人的姓名中出现过(在名中出现或在姓中出现, ...

  6. C、CSL 的密码 【set暴力 || 后缀数组】 (“新智认知”杯上海高校程序设计竞赛暨第十七届上海大学程序设计春季联赛 )

    题目传送门:https://ac.nowcoder.com/acm/contest/551/C 题目描述 众所周知,CSL 最喜欢的密码是 ******.于是有一天……     为了改变这一点,他决定 ...

  7. BZOJ.4516.[SDOI2016]生成魔咒(后缀数组 RMQ)

    题目链接 后缀自动机做法见这(超好写啊). 后缀数组是可以做的: 本质不同的字符串的个数为 \(子串个数-\sum_{ht[i]}\),即 \(\frac{n(n+1)}{2}-\sum_{ht[i] ...

  8. HDU 4691 Front compression (2013多校9 1006题 后缀数组)

    Front compression Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Othe ...

  9. hdu4691(后缀数组)

    算是后缀数组的入门题吧. 思路无比简单,要是直接套模板的话应该很容易秒掉. 关于后缀数组看高中神犇的论文就可以学会了 算法合集之<后缀数组——处理字符串的有力工具> 话说这题暴力是可以过了 ...

随机推荐

  1. 初识onselectstart

    onselectstart几乎可以用于所有对象,其触发时间为目标对象被开始选中时(即选中动作刚开始,尚未实质性被选中). 实例: 在做拖拽效果的时候,为了防止js选中页面上的其他元素,onselect ...

  2. [bzoj2124]等差子序列(hash+树状数组)

    我又来更博啦     2124: 等差子序列 Time Limit: 3 Sec  Memory Limit: 259 MBSubmit: 941  Solved: 348[Submit][Statu ...

  3. C# 使用HttpWebRequest通过PHP接口 上传文件

    1:上传文件实例 public void UploadXMLLog(string xmlpath)         {             NameValueCollection nvc = ne ...

  4. jQuery之元素操作及事件绑定

    1.操作元素之属性: ①attr读:("selector").attr("属性名"):=>getAttribute("属性名"):改: ...

  5. centos 安装 mongdb

    1.安装MongoDB(安装到/usr/local) wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon-3.2.4.t ...

  6. Centos7 搭建 Keepalived+LVS 备注

    NAT模型需要RealServer gateway设定为,DR模式需要执行 RealServer.sh.需要先安装network-tools. #!/bin/bash#description : st ...

  7. vue学习笔记之属性和方法

    每个Vue都会代理其data对象里所有的属性:只有这些被代理的属性是响应的.如果在实例创建之后添加新的属性到实例上,它不会触发视图更新.例子: <script type="text/j ...

  8. C/C++-----------http协议发送字段,文件,单个和多张图片

    关于c/c++ 网络编程,无论在linux还是windows,要说到自由性,和安全性,socket无疑是比较好的!对于socket,因为它的传输协议只有两种tcp和udp,属于网络层,这里我们不去重点 ...

  9. HTML“计算机输出”标签 <code><kbd><samp><tt><var><pre>

    我们并不反对使用它们,但是如果您只是为了达到某种视觉效果而使用这些标签的话,我们建议您使用样式表,那么做会达到更加丰富的效果. <code> 标签-定义计算机代码文本. 定义和用法: &l ...

  10. Windows Store App 插值动画

    插值动画支持DoubleAnimation.ColorAnimation和PointAnimation类型的动画.其中比较常用的是DoubleAnimation动画,它可以用来控制界面元素的Doubl ...