Atcoder arc059_b

题目链接

题目描述

给定字符串S,求出S的一个子集,使得其中某一的字母的数量大于该子集字母数量的一半
若存在输出该子集的头和尾的坐标,若不存在则输出两个 $ -1 $

数据范围:

$ 2≦|S|≦10^5 $
$ S $ consists of lowercase letters.

思路

1.暴力

发现每一个满足题意的S都一定包含一个长度为2或3的满足题意的子串
也就是说只需要暴力查找一遍即可

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#define ll long long
#define ull unsigned long long
#define ci const int&
#define cl const long long&
#define cul const unsigned long long&
#define io_f std::ios::sync_with_stdio(false)
using namespace std;

string a;

int main() {
    cin >> a;
    int le = a.size();
    for (int i = 0; i < le - 1; i++) {
        if (a[i] == a[i+1]) {
            cout << i+1 << ' ' << i+2 << endl;
            return 0;
        } else if (a[i] == a[i+2] && i != le - 2) {
            cout << i+1 << ' ' << i+3 << endl;
            return 0;
        }
    }
    cout << -1 << ' ' << -1 << endl;
    return 0;
}

转载于:https://www.cnblogs.com/ullio/p/9663549.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值