https://www.luogu.org/problemnew/show/U18590

后缀数组???

不会

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <map> using namespace std;
const int N = 1e3 + ; #define yxy getchar()
#define R freopen("gg.in", "r", stdin) char s[N];
int sum[N], len, js, Answer;
struct Node{
string s;
int l, r, w, num;
}A[N * N];
struct Node_2{
int l, r;
}Ans[N * N];
map <string, bool> mp; inline int read(){
int x = ; char c = yxy;
while(c < '' || c > '') c = yxy;
while(c >= '' && c <= '') x = x * + c - '', c = yxy;
return x;
} bool cmp(Node a, Node b) {return a.s > b.s;}
bool cmp2(Node_2 a, Node_2 b) {return a.l < b.l;} string get_string(int l, int r){
string ret;
for(int i = l; i <= r; i ++) ret += s[i];
return ret;
} int main()
{
scanf("%s", s + );
len = strlen(s + );
for(int i = ; i <= len; i ++) sum[i] = read(), sum[i] += sum[i - ];
for(int i = ; i <= len; i ++){
for(int j = i; j <= len; j ++){
string ss = get_string(i, j);
A[++ js].s = ss;
A[js].l = i; A[js].r = j; A[js].w = sum[j] - sum[i - ];
}
}
sort(A + , A + js + , cmp);
int px();
A[].num = ;
for(int i = ; i <= js; i ++)
if(A[i].s != A[i - ].s) A[i].num = ++ px;
else A[i].num = px;
for(int i = ; i <= js; i ++)
if(A[i].num == A[i].w) {
Ans[++ Answer].l = A[i].l;
Ans[Answer].r = A[i].r;
}
sort(Ans + , Ans + Answer + , cmp2);
printf("%d\n", Answer);
for(int i = ; i <= Answer; i ++) printf("%d %d\n", Ans[i].l, Ans[i].r);
return ;
}
/*
aaaa
1 1 1 1
*/

[Luogu] U18590 采集矿石的更多相关文章

  1. [Luogu P4143] 采集矿石 [2018HN省队集训D5T3] 望乡台platform

    [Luogu P4143] 采集矿石 [2018HN省队集训D5T3] 望乡台platform 题意 给定一个小写字母构成的字符串, 每个字符有一个非负权值. 输出所有满足权值和等于这个子串在所有本质 ...

  2. 【刷题】洛谷 P4143 采集矿石

    题目背景 ZRQ成功从坍塌的洞穴中逃了出来.终于,他看到了要研究的矿石.他想挑一些带回去完成任务. 题目来源:Zhang_RQ哦对了ZRQ就他,嗯 题目描述 ZRQ发现这里有 \(N\) 块排成一排的 ...

  3. 洛谷 P4143 采集矿石 后缀数组

    题目背景 ZRQ 成功从坍塌的洞穴中逃了出来.终于,他看到了要研究的矿石.他想挑一些带回去完成任务. 题目来源:Zhang_RQ哦对了 \(ZRQ\) 就他,嗯 题目描述 ZRQ 发现这里有 \(N\ ...

  4. 题解 洛谷 P4143 【采集矿石】

    对于一个固定的左端点,右端点向右移动时,其子串权值和不断增大,字典序降序排名不断减小,因此对于一个左端点,最多存在一个右端点使其满足条件. 所以可以枚举左端点,然后二分右端点的位置,权值和通过前缀和来 ...

  5. 《HelloGitHub》第 75 期

    兴趣是最好的老师,HelloGitHub 让你对编程感兴趣! 简介 HelloGitHub 分享 GitHub 上有趣.入门级的开源项目. https://github.com/521xueweiha ...

  6. Luogu P1447 [NOI2010]能量采集

    Preface 最近反演题做多了看什么都想反演.这道题由于数据弱,解法多种多样,这里简单分析一下. 首先转化下题目就是对于一个点\((x,y)\),所消耗的能量就是\(2(\gcd(x,y)-1)+1 ...

  7. [计蒜客] 矿石采集【记搜、Tarjan缩点+期望Dp】

    Online Judge:计蒜客信息学3月提高组模拟赛 Label:记搜,TarJan缩点,树状数组,期望Dp 题解 整个题目由毫无关联的两个问题组合成: part1 问题:对于每个询问的起点终点,求 ...

  8. Luogu P1447 [NOI2010]能量采集 数论??欧拉

    刚学的欧拉反演(在最后)就用上了,挺好$qwq$ 题意:求$\sum_{i=1}^{N}\sum_{j=1}^{M}(2*gcd(i,j)-1)$ 原式 $=2*\sum_{i=1}^{N}\sum_ ...

  9. luogu P1447 [NOI2010]能量采集 欧拉反演

    题面 题目要我们求的东西可以化为: \[\sum_{i=1}^{n}\sum_{j=1}^{m}2*gcd(i,j)-1\] \[-nm+2\sum_{i=1}^{n}\sum_{j=1}^{m}gc ...

随机推荐

  1. docker 实践四:仓库管理

    本篇我们来了解 docker 仓库的内容. 注:环境为 CentOS7,docker 19.03 仓库(Responsitory)是集中存放镜像的地方,又分公共仓库和私有仓库. 注:有时候容易把仓库与 ...

  2. mybatis相关知识积累

    mybatis Statement Statement对象用于将 SQL 语句发送到数据库中. 实际上有三种 Statement 对象,它们都作为在给定连接上执行 SQL语句的包容器: Stateme ...

  3. Bootstrap3 CDN 使用手册

    一.一般功能 <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.css" rel=" ...

  4. python打印表格式数据-星号或注释

    python打印表格式数据,留出正确的空格,格式化打出 代码如下: def printPicnic(itemsDict,leftWidth,rightWidth): print('PICNIC ITE ...

  5. oracle学习笔记:字符串替换 replace、regexp_replace、translate函数

    1.replace 函数 语法:replace(char, search_string, replacement_string) --针对字符串替换 功能: ​ 将char中的字符串替换. ​ 当re ...

  6. 基于vue的购物车清单

    <!doctype html> <html> <head> <meta charset="utf-8"> <link rel= ...

  7. xposed获取context 的方法

    // 应用被加壳,采用这种方式加载类 try { XposedHelpers.findAndHookMethod(Application.class, "attach", Cont ...

  8. vue中用div的contenteditable属性实现v-for遍历,双向数据绑定的动态表格编辑

    1.HTML部分 <tr v-for="(item,index) in customerVisitList2" :key="index"> < ...

  9. pymysql 1064, 'You have an error in your SQL syntax; check the manual that corresponds to

    在python 连接mysql时,最近一直出现了 1064, 'You have an error in your SQL syntax; check the manual that correspo ...

  10. Thymeleaf整合到Spring Security,标签sec不起作用

    将 pom 文件中的 thymeleaf-extras-springsecurity4 依赖改成  thymeleaf-extras-springsecurity5 <dependency> ...