Codeforces #349 div1 A. Reberland Linguistics 模拟 递推

题目

题目链接:http://codeforces.com/contest/666/problem/A

题目来源:Codeforces #349 div1

题解

英文是硬伤,twice in a row竟然是连续两次,赛后两眼泪汪汪。

首先肯定是用个set去存,比较方便。

反向扫,根据可行性进行递推,就去看+2,+3的位置是否可以进行递推。

连续两次的条件就去判断能否在之后用不同长度构造,或者相同长度字符不同。

代码

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
// head
const int N = 1e4+5;

char s[N];
char temp[15];
bool a[N];

set<string> ma;

int main() {
    scanf("%s", s);
    int n = strlen(s);
    a[n] = true;
    for (int i = n-2; i > 4; i--) {
        if (a[i+2]) {
            for (int j = 0; j < 2; j++) {
                temp[j] = s[i+j];
            }
            temp[2] = '\0';
            string ss = temp;
            ma.insert(ss);
            if (strstr(s+i+2, temp) != s+i+2 || a[i+5]) a[i] = true;
        }
        if (a[i+3]) {
            for (int j = 0; j < 3; j++) {
                temp[j] = s[i+j];
            }
            temp[3] = '\0';
            string ss = temp;
            ma.insert(ss);
            if (strstr(s+i+3, temp) != s+i+3 || a[i+5]) a[i] = true;
        }
    }
    printf("%d\n", ma.size());
    for (auto it : ma) {
        printf("%s\n", it.c_str());
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值