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 ...
随机推荐
- android 截取指定位置字符串
String str = "s\ziyuan"; String newStr = str.subString(str.indexOf("\\"),str.len ...
- 普通的101键盘在Mac上的键位对应
为了方便,搞了一个普通的101有线全键盘 + Magic TrackPad配Macbook. 然后发现了一个小问题,按键对应似乎不像我想的那么完美,F1~F12和Macbook不对应,于 ...
- JQuery 插件 - 弹窗:BlockUI
JQuery的弹窗插件,网上实在有很多做的比较好的,比如artDialog.layer,甚至EasyUI等等.这些在效果上做的非常好.但我觉得一个小小的弹窗提示,没有必要引用这些(其实是有点大材小用了 ...
- Android样式的编写格式
<?xml version="1.0" encoding="utf-8"?> <resources> <style name=&q ...
- Android取得屏幕的高度和宽度
//获得手机屏幕的宽度和高度 width=getWindowManager().getDefaultDisplay().getWidth(); height=getWindowManager().ge ...
- sicily 4433 DAG?
题意:输入一个有向图,判断该图是否是有向无环图(Directed Acyclic Graph). 解法:还是深搜 #include<iostream> #include<memory ...
- 回调函数的意义以及python实现
因工作需要,最近在学习使用python来解析各种文件,包括xmind,xml,excel,csv等等. 在学习python解析XML的时候看到这样一段话: 3.ElementTree(元素树) Ele ...
- Sublime Text 3配置记录
G++ /** * 工具->编译系统->新编译系统 */ { "cmd": ["g++", "${file}", "- ...
- 我为什么要再给lua写一个json模块
最近要给自己编写的服务器加上json解析模块.根据我当前的项目,可以预测服务器中使用json的地方: 通信.由于与客户端通信使用google protocolbuffer,仅在与SDK通信中使用jso ...
- Python进阶(面向对象编程基础)(四)
1.方法也是属性 我们在 class 中定义的实例方法其实也是属性,它实际上是一个函数对象: class Person(object): def __init__(self, name, score) ...