题目链接:http://abc043.contest.atcoder.jp/tasks/arc059_b

Time limit : 2sec / Memory limit : 256MB

Score : 400 points

Problem Statement

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

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

Constraints

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

Partial Score

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

Input

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

s

Output

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

If there exists an unbalanced substring of s, let one such substring be sasa+1…sb (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
needed

Sample Output 1

Copy
2 5

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


Sample Input 2

Copy
atcoder

Sample Output 2

Copy
-1 -1

The string atcoder contains no unbalanced substring.

题意:给定一个序列,如果某个子序列中的有一个字母的数量大于子序列长度的一半则为平衡序列。

题解:其实本题只要判断了相邻两个字母是否一样或者间隔一个的字母是否相同就能判断出是否有子序列满足平衡。在往后判断只是重复了上述的情况

 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
bool cmp(int x,int y)
{
return x>y;
}
const int N=;
const int mod=1e9+;
int main()
{
std::ios::sync_with_stdio(false);
cin.tie();
int flag=;
string s;
cin>>s;
for(int i=;i<s.size()-;i++){
if(s[i]==s[i+]){
cout<<i+<<" "<<i+<<endl;
flag=;
break;
}
else if(i<s.size()-&&s[i]==s[i+]){
cout<<i+<<" "<<i+<<endl;
flag=;
break;
}
}
if(!flag)
cout<<-<<" "<<-<<endl;
return ;
}

AtCoder Beginner Contest 043 D - アンバランス / Unbalanced的更多相关文章

  1. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  2. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  3. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  4. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

  5. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  6. AtCoder Beginner Contest 076

    A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...

  7. AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】

    AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...

  8. AtCoder Beginner Contest 064 D - Insertion

    AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...

  9. AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle【暴力】

    AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle 我要崩溃,当时还以为是需要什么离散化的,原来是暴力,特么五层循环....我自己写怎么都 ...

随机推荐

  1. 张小龙2018PRO版微信公开课演讲全文 透露2018微信全新计划

    大家好!我是张小龙.欢迎大家来到微信公开课. 刚刚出现的是我打游戏的画面,被大家看到了,那个不是我最好的水平,因为有点紧张,我最高分曾打到6000多分.当然我是练习了很久了,并不是我比大家更厉害,而是 ...

  2. Windows server 2016 支持容器 ,安装docker 搭建Ubuntu+hadoop (docker为服务器)

    一.Windows server 2016 是肯定要安装的, 关于如何启动容器功能那就是控制面板中增加与删除里面的启用了,很多地方可以百度到 二. 安装Ubuntu hadoop 等  待续 注意: ...

  3. python安装talib库

    简便安装方法 最简单的安装方式: $ pip install TA-Lib 用setup.py的方式自己安装一个源文件 $ python setup.py install 有可能遇到的问题 func. ...

  4. 【分类器】感知机+线性回归+逻辑斯蒂回归+softmax回归

    一.感知机     详细参考:https://blog.csdn.net/wodeai1235/article/details/54755735 1.模型和图像: 2.数学定义推导和优化: 3.流程 ...

  5. 模拟django配置环境进行数据增删改查,测试的时候有用

    import os if __name__ == '__main__': os.environ.setdefault('DJANGO_SETTINGS_MODULE','day76.settings' ...

  6. [vue]模拟移动端三级路由: router-link位置体现router的灵活性

    小结 router-link可以随便放 router-view显示的是父组件的直接子组件的内容 想研究下移动三级路由的逻辑, 即 router-link和router-view 点首页--点新闻资讯( ...

  7. 第一弹:超全Python学习资源整理(入门系列)

    随着人工智能.大数据的时代到来,学习Python的必要性已经显得不言而喻.我经常逛youtube,发现不仅仅是以编程为职业的程序员,证券交易人员,生物老师,高级秘书......甚至许多自由撰稿人,设计 ...

  8. @Value("#{}") 和 @Value("{}")

    1 @Value("#{}")   SpEL表达式 @Value("#{}") 表示SpEl表达式通常用来获取bean的属性,或者调用bean的某个方法.当然还 ...

  9. linux统计文件夹大小

    统计总大小: du -sh dirname 统计文件夹内部各文件大小及总大小: du -h dirname

  10. iOS 开发笔记-报错处理

    1.xcode7报错:does not contain bitcode 解决方法:Build Settings 搜索 bitcode  将Enable Bitcode更改为NO即可 2.Code Si ...