D - アンバランス / Unbalanced(思维,开始没想到)

 

题目描述:

                                                      D - アンバランス / Unbalanced

Time Limit: 2 sec / Memory Limit: 256 MB

Score : 400400 points

Problem Statement

Given a string tt, we will call it unbalanced if and only if the length of tt is at least 22, and more than half of the letters in tt are the same. For example, both voodoo and melee are unbalanced, while neither noon nor a is.

You are given a string ss consisting of lowercase letters. Determine if there exists a (contiguous) substring of ss that is unbalanced. If the answer is positive, show a position where such a substring occurs in ss.

Constraints

  • 2≦|s|≦1052≦|s|≦105
  • ss consists of lowercase letters.

Partial Score

  • 200200 points will be awarded for passing the test set satisfying 2≦N≦1002≦N≦100.

Input

The input is given from Standard Input in the following format:

ss

Output

If there exists no unbalanced substring of ss, print -1 -1.

If there exists an unbalanced substring of ss, let one such substring be sasa+1...sbsasa+1...sb (1≦a<b≦|s|)(1≦a<b≦|s|), and print \(a\) \(b\). If there exists more than one such substring, any of them will be accepted.

Sample Input 1 Copy

Copy

needed

Sample Output 1 Copy

Copy

2 5

The string s2s3s4s5s2s3s4s5 == eede is unbalanced. There are also other unbalanced substrings. For example, the output 2 6 will also be accepted.

Sample Input 2 Copy

Copy

atcoder

Sample Output 2 Copy

Copy

-1 -1

The string atcoder contains no unbalanced substring.

题目大意:

       在原串中找一个字串,该字串中某一个字符的个数占该字串长度一半以上。

思路:

       要占据一半以上,要么相邻的两个一样,最坏情况下也得每隔一位出现一次。

所以直接考虑2位或者3位的字串即可,

开始没想到这个思路,只会暴力。。。

代码实现:

#include<bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
#define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int N=2e5+100;
using namespace std;
int main()
{
	io;
	string str;
	while(cin>>str)
	{
		int len=str.length();
		int f=0;
		for(int i=0;i<=len-1;i++)
		{
			if(str[i]==str[i+1]&&i+1<len)
			{
				f=1;
				cout<<i+1<<" "<<i+2<<endl;
				break;
			}
			else if(str[i]==str[i+2]&&i+2<len)
			{
				cout<<i+1<<" "<<i+3<<endl;
				f=1;
				break;
			}
		}
		if(f==0)cout<<-1<<" "<<-1<<endl;
	}
	return 0;
}

The end;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值