AtCoder Beginner Contest 043 D - アンバランス / Unbalanced
题目链接: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
needed
Sample Output 1
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
atcoder
Sample Output 2
-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的更多相关文章
- AtCoder Beginner Contest 100 2018/06/16
A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...
- AtCoder Beginner Contest 052
没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 136
AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...
- AtCoder Beginner Contest 137 F
AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...
- AtCoder Beginner Contest 076
A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...
- AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】
AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...
- AtCoder Beginner Contest 064 D - Insertion
AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...
- AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle【暴力】
AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle 我要崩溃,当时还以为是需要什么离散化的,原来是暴力,特么五层循环....我自己写怎么都 ...
随机推荐
- 20180409 Code First
many people use DB First,Today I see Code First. 这部分,百度上面有更多详细的资料,虽然不明白Migrations内部的机制,但是还是可以记录一下 打 ...
- SQL SERVER 2016研究四
SQL Server 2016 白皮书 内容:内存优化表 问题? -----内存优化表在2014版本推出,主要是如何作用?如何使用?目前有何变化? 内存优化表是可以将表放入内存中,能提升操作性能. - ...
- LVS基础知识
LVS介绍(Linux Virtual Server) 负载调度器,已经集成到内核 工作原理:VS根据请求报文的目标IP和目标协议及端口将其调度转发至某RS,根据调度算法来挑选RS iptables/ ...
- VirtualBox 在Win10上的蓝屏问题
今天也是第一次使用VirtualBox ,因为比VM更轻量,当然主要还是版权,结果装完虚拟机后,每次打开虚拟机就蓝屏,系统报错. 这是出现在WIN10上的问题啊. 解决办法: 找到Control Pa ...
- mybatis之注解式开发
注解: 注解是用于描述代码的代码.例如:@Test(用于描述方法进行junit测试),@Override(用于描述方法的重写),@Param(用于描述属性的名称) 注解的使用风格:@xxx(属性),使 ...
- sqli-labs(三)
第五关:这关的重点是有联合查询的注入漏洞,但是页面不会显示查询信息,但是会有报错信息显示在页面上 这关是双查询注入,其实用报错注入和盲注都是可以注入的,但是我觉得这个双查询注入还是很有意思的,所以这关 ...
- laravel学习历程
1.www目录下拉下来一个laravel框架 composer create-project laravel/laravel laravelapp --prefer-dist laravelapp 为 ...
- python 定义函数 调用函数
创建test.py文件 #coding=utf-8 #定义函数 def hello(): print "hello world" #调用函数 hello() 在cmd下面运行
- Linux的文件最大连接数
[最大连接数]Linux的文件最大连接数 查看当前操作系统连接数设置 ulimit -a ==================================== 修改服务器最大连接数 vim / ...
- Javascript-可莱托指数判断
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...