hdu4691 Front compression ——暴力 || 后缀数组
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 ——暴力 || 后缀数组的更多相关文章
- hdu 4691 Front compression (后缀数组)
hdu 4691 Front compression 题意:很简单的,就是给一个字符串,然后给出n个区间,输出两个ans,一个是所有区间的长度和,另一个是区间i跟区间i-1的最长公共前缀的长度的数值的 ...
- HDU 4691 Front compression(后缀数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4691 题意:给出Input,求出Compressed output.输出各用多少字节. 思路:求后缀数 ...
- hdu4691 Front compression(后缀数组)
Front compression Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others) ...
- HDU-4691 Front compression 后缀数组
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4691 后缀数组模板题,求出Height数组后,对Height做RMQ,然后直接统计就可以了... // ...
- BZOJ_2754__[SCOI2012]_喵星球上的点名_(暴力+后缀数组)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=2754 给出n个姓名串和m个点名串.求每个点名串在多少人的姓名中出现过(在名中出现或在姓中出现, ...
- C、CSL 的密码 【set暴力 || 后缀数组】 (“新智认知”杯上海高校程序设计竞赛暨第十七届上海大学程序设计春季联赛 )
题目传送门:https://ac.nowcoder.com/acm/contest/551/C 题目描述 众所周知,CSL 最喜欢的密码是 ******.于是有一天…… 为了改变这一点,他决定 ...
- BZOJ.4516.[SDOI2016]生成魔咒(后缀数组 RMQ)
题目链接 后缀自动机做法见这(超好写啊). 后缀数组是可以做的: 本质不同的字符串的个数为 \(子串个数-\sum_{ht[i]}\),即 \(\frac{n(n+1)}{2}-\sum_{ht[i] ...
- HDU 4691 Front compression (2013多校9 1006题 后缀数组)
Front compression Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Othe ...
- hdu4691(后缀数组)
算是后缀数组的入门题吧. 思路无比简单,要是直接套模板的话应该很容易秒掉. 关于后缀数组看高中神犇的论文就可以学会了 算法合集之<后缀数组——处理字符串的有力工具> 话说这题暴力是可以过了 ...
随机推荐
- JPA入门案例详解(附源码)
1.新建JavaEE Persistence项目
- iOS - Project 项目
1.项目流程 1.1 分析项目的架构 iOS 常见的几种架构 标签式 Tab Menu 列表式 List Menu 抽屉式 Drawer 瀑布式 Waterfall 跳板式 Springborad 陈 ...
- 进程、线程、socket套接字-资源大小 & 切换代价
另,进程 & 线程的很多知识可以看这里:http://www.cnblogs.com/charlesblc/p/6135666.html 今天查了一下进程和线程的资源占用. 比如问:栈和堆的大 ...
- 基于注解的Spring AOP的配置和使用--转载
AOP是OOP的延续,是Aspect Oriented Programming的缩写,意思是面向切面编程.可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术. ...
- Android之alertDialog、ProgressDialog
一.alertDialog 置顶于所有控件之上的,可以屏蔽其他控件的交互能力.通过AlertDialog.Builder创建一个AlertDialog,并通过setTittle(),setMesseg ...
- urlencode 和 rawurlencode 的区别
urlencode和rawurlencode的区别urlencode和rawurlencode的区别 $str1 = urlencode(':/?= &#'); $str2 = rawurle ...
- python核心编程第六章练习6-10
6-10.字符串.写一个函数,返回一个跟输入字符串相似的字符串,要求字符串的大小写反转,比如,输入“Mr.Ed”,应该返回“mR.eD”作为输出.[答案]代码如下: #!/usr/bin/env py ...
- callee
首先解释callee 参考网站 http://www.css88.com/archives/1706 callee是arguments的一个成员,仅当函数正在执行的时候才可用,so用于递归也行 代码示 ...
- 并发编程 13—— 线程池的使用 之 配置ThreadPoolExecutor 和 饱和策略
Java并发编程实践 目录 并发编程 01—— ThreadLocal 并发编程 02—— ConcurrentHashMap 并发编程 03—— 阻塞队列和生产者-消费者模式 并发编程 04—— 闭 ...
- iPhone/iPad/Android UI尺寸规范
iPhone界面尺寸