题目链接: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. 组合覆盖与PICT的使用

    组合覆盖法是一种有效减少测试用例个数的测试用例设计方法.根据覆盖程度的不同,可以分为单因素覆盖.成对组合覆盖.三三组合覆盖等.其中又以成对组合覆盖最常用. 关于组合覆盖的更多内容,参考:http:// ...

  2. 002-MVC架构,贫血的领域模型、spring mvc,webhars使用

    一.MVC.贫血的领域模型 MVC理念是将视图与模型进行解耦. 贫血的领域模型 <领域驱动设计>定义了一组架构规则,能够指导我们更好地将业务领域集成到代码中. 其中一个核心理念是将面向对象 ...

  3. 照葫芦画瓢之爬虫豆瓣top100

    import requestsimport reimport jsonfrom requests.exceptions import RequestExceptiondef get(url):    ...

  4. vue.js 兄弟组件传值

    另:  在vue里,组件之间的作用域是独立的,父组件跟子组件之间的通讯可以通过prop属性来传参,但是在兄弟组件之间通讯就比较麻烦了,虽然可以使用事件监听的方式,但还是不如vuex专业.比如A组件要告 ...

  5. SAP 从数据库中查询数据,带有where 条件。

    数据库表 代码 *& Report ZSELECT_DATA_FROM_ZMAST_CUST *&------------------------------------------- ...

  6. DL中train\dev\test集

    转自:https://blog.csdn.net/l8947943/article/details/80328721 training set:训练集是用来训练模型的.遵循训练集大,开发,测试集小的特 ...

  7. CentOS6.5安装kafka-2.10-0.8.2(单机)

    1.下载 地址:https://kafka.apache.org/downloads 本文中下载版本:kafka_2.10-0.8.2.2.tgz 2.安装 安装目录:/usr/local [root ...

  8. linux统计文件夹大小

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

  9. vue路由(一个包含重定向、嵌套路由、懒加载的main.js如下)and 路由跳转传参的query和params的异同

    import Vue from 'vue'import VueRouter from 'vue-router'import App from './App'Vue.use(VueRouter)cons ...

  10. sqli-labs(十三)(hpp)

    第二十九关 这关说的是有waf,其实只是模拟waf的场景,就是说waf处理的变量和后台程序接受的变量不一致. 考验的参数污染,具体可以参考其他文章关于HPP的解释. 先看源码吧: 输入?id=1&am ...