cf C. Sereja and Algorithm
http://codeforces.com/contest/368/problem/C
从左向右记录从1位置到每一个位置上x,y,z的个数。然后判断在l,r区间内的x,y,z的关系满不满足abs(x-y)<=1&&abs(x-z)<=1&&abs(y-z)<=1,满足输出YES,否则输出NO。
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 200000
using namespace std; char str[maxn];
int hx[maxn],hy[maxn],hz[maxn];
int m;
int l,r; int main()
{
while(scanf("%s",str)!=EOF)
{
int t1=,t2=,t3=;
memset(hx,,sizeof(hx));
memset(hy,,sizeof(hy));
memset(hz,,sizeof(hz));
int len=strlen(str);
for(int i=; i<len; i++)
{
if(str[i]=='x')
{
t1++;
hx[i+]=t1;
hy[i+]=t2;
hz[i+]=t3;
}
else if(str[i]=='y')
{
t2++;
hx[i+]=t1;
hy[i+]=t2;
hz[i+]=t3;
}
else if(str[i]=='z')
{
t3++;
hx[i+]=t1;
hy[i+]=t2;
hz[i+]=t3;
}
}
scanf("%d",&m);
for(int i=; i<=m; i++)
{
scanf("%d%d",&l,&r);
int len=r-l+;
if(len<)
{
printf("YES\n");
continue;
}
else
{
int x=hx[r]-hx[l-];
int y=hy[r]-hy[l-];
int z=hz[r]-hz[l-];
if(abs(x-y)<=&&abs(x-z)<=&&abs(y-z)<=)
{
printf("YES\n");
}
else printf("NO\n");
}
}
}
return ;
}
cf C. Sereja and Algorithm的更多相关文章
- Codeforces Round #215 (Div. 2) C. Sereja and Algorithm
#include <iostream> #include <vector> #include <algorithm> #include <string> ...
- cf D. Sereja ans Anagrams
http://codeforces.com/contest/368/problem/D #include <cstdio> #include <cstring> #includ ...
- cf B. Sereja and Suffixes
http://codeforces.com/contest/368/problem/B 从后往前找一遍就可以. #include <cstdio> #include <cstring ...
- CF 314C Sereja and Subsequences(树状数组)
题目链接:http://codeforces.com/problemset/problem/314/C 题意:给定一个数列a.(1)写出a的不同的所有非下降子列:(2)定义某个子列的f值为数列中各个数 ...
- 【CF】Sereja and Arcs
#include <bits/stdc++.h> #define llong long long using namespace std; const int N = 1e5; const ...
- Android 签名比较
一. keytool -list -printcert -jarfile "%filename%" 二. 非常low方法:下载的应用安装能成功覆盖原应用则签名一致三. 作者:陈子腾 ...
- Codeforces 367
A. Sereja and Algorithm 水题不解释. B. Sereja ans Anagrams 模p同余的为一组,随便搞. C. Sereja and the Arrangement of ...
- Codeforces Round #215 (Div. 1)
A Sereja and Algorithm 题意:给定有x,y,z组成的字符串,每次询问某一段s[l, r]能否变成变成zyxzyx的循环体. 分析: 分析每一段x,y,z数目是否满足构成循环体,当 ...
- 如何判断 Android 应用的 Apk 签名是否一致?
可以比对apk签名的fingerprint. 假定安装了JDK,如果想查HelloWorld.apk所使用的签名的fingerprint,可以这样做: 1. 查找apk里的rsa文件 (Windows ...
随机推荐
- ListView的getFirstVisiblePosition等方法返回的是哪个对象
int firstPosition = lisView.getFirstVisiblePosition(); int lastPosition = lisView.getLastVisiblePosi ...
- Set的并集
public static void main(String[] args) { Set<Long> old = new HashSet<>(); for (int i = 0 ...
- HDOJ 1196 Lowest Bit(二进制相关的简单题)
Problem Description Given an positive integer A (1 <= A <= 100), output the lowest bit of A. F ...
- HDU-1176(基础方程DP)
Problem Description 都 说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼别处都不掉, 就掉落在他 ...
- RSA算法python实现
RSA算法是一种非对称加密算法,是现在广泛使用的公钥加密算法,主要应用是加密信息和数字签名.详情请看维基:http://zh.wikipedia.org/wiki/RSA%E5%8A%A0%E5%AF ...
- 简单Mysql思维导图
- java,大数据批量插入、更新
public void exec(Connection conn){ try { conn.setAutoCommit(false); Long beginTime = System.currentT ...
- 关于在centos7上安装vmtools的各种报错的问题处理
基本上如果安装vmtools时报错的错,首先记录一下报错信息 例如,本次遇见的就是 /tmp/modconfig-8mD7iy/vmhgfs-only/page.c:1625:23: 错误:提供给函数 ...
- java中jvm的工作原理
首先我们安装了jdk和jre,但是jdk是为java软件开发工程师而使用的开发工具,我们运行java项目只要含有jre文件即可.对于jvm是内存分配的一块区域,我们知道,当我们开始使用java命令时, ...
- 数据库和linq中的 join(连接)操作
sql中的连接 sql中的表连接有inner join,left join(left outer join),right join(right outer join),full join(full o ...