码迷,mamicode.com
首页 > 其他好文 > 详细

[Luogu] U18590 采集矿石

时间:2018-01-21 14:43:52      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:tps   tar   color   efi   names   turn   ace   printf   while   

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 + 10;

#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 = 0; char c = yxy;
    while(c < 0 || c > 9) c = yxy;
    while(c >= 0 && c <= 9) x = x * 10 + c - 0, 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 + 1);
    len = strlen(s + 1);
    for(int i = 1; i <= len; i ++) sum[i] = read(), sum[i] += sum[i - 1];
    for(int i = 1; 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 - 1];
        }
    }
    sort(A + 1, A + js + 1, cmp);
    int px(1);
    A[1].num = 1;
    for(int i = 2; i <= js; i ++)
        if(A[i].s != A[i - 1].s) A[i].num = ++ px;
        else A[i].num = px;
    for(int i = 1; i <= js; i ++)
        if(A[i].num == A[i].w) {
            Ans[++ Answer].l = A[i].l;
            Ans[Answer].r = A[i].r;
        }
    sort(Ans + 1, Ans + Answer + 1, cmp2);
    printf("%d\n", Answer);
    for(int i = 1; i <= Answer; i ++) printf("%d %d\n", Ans[i].l, Ans[i].r);
    return 0;
}
/*
aaaa
1 1 1 1
*/

 

[Luogu] U18590 采集矿石

标签:tps   tar   color   efi   names   turn   ace   printf   while   

原文地址:https://www.cnblogs.com/shandongs1/p/8324041.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!