A. Two Substrings
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).

Input

The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.

Output

Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.

Examples
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
Note

In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".

In the second sample test there are the following occurrences of the substrings: BACFAB.

In the third sample test there is no substring "AB" nor substring "BA".

题意:判断字符串中是否有两个不重叠的“AB”"BA"有则输出“YES” 否则输出“NO”

题解:模拟判断,标记。

 #include<bits/stdc++.h>
using namespace std;
#define ll __int64
int n;
char a[];
map<int,int>mp1;
map<int,int>mp2;
int main ()
{
scanf("%s",a);
int len=strlen(a);
int flag1=,flag2=,flag3=,flag4=;
for(int i=;i<len-;i++)
{
if(a[i]=='A'&&a[i+]=='B')
{
mp1[i+]=;
mp2[i]=;
flag1=;
break;
}
}
for(int i=;i<len-;i++)
{
if(mp1[i]==&&mp2[i+]==&&a[i]=='B'&&a[i+]=='A')
{
flag2=;
break;
}
}
mp1.clear();
mp2.clear();
for(int i=;i<len-;i++)
{
if(a[i]=='B'&&a[i+]=='A')
{
mp1[i+]=;
mp2[i]=;
flag3=;
break;
}
}
for(int i=;i<len-;i++)
{
if(mp1[i]==&&mp2[i+]==&&a[i]=='A'&&a[i+]=='B')
{
flag4=;
break;
}
}
if((flag1==&&flag2==)||(flag3==&&flag4==))
printf("YES\n");
else
printf("NO\n");
return ;
}
B. Preparing Olympiad
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You have n problems. You have estimated the difficulty of the i-th one as integer ci. Now you want to prepare a problemset for a contest, using some of the problems you've made.

A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.

Find the number of ways to choose a problemset for the contest.

Input

The first line contains four integers n, l, r, x (1 ≤ n ≤ 15, 1 ≤ l ≤ r ≤ 109, 1 ≤ x ≤ 106) — the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.

The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 106) — the difficulty of each problem.

Output

Print the number of ways to choose a suitable problemset for the contest.

Examples
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
Note

In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.

In the second example, two sets of problems are suitable — the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.

In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable.

题意:给你n个数,选取若干个数,使得数的和在[l,r]的范围内 并且最大值与最小值的差值大于等于x  问有多少种选择的方案

题解:n为15 共有(2^15)中选择方案 枚举check。

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
using namespace std;
int n,l,r,x;
int a[];
int main()
{
scanf("%d %d %d %d",&n,&l,&r,&x);
for(int i=;i<n;i++)
scanf("%d",&a[i]);
int cnt=<<n;
int ans=;
for(int i=;i<cnt;i++)
{
int minx=1e9+,maxn=-;
int exm=i;
int sum=;
int jishu=;
while(exm>)
{
//cout<<exm<<endl;
if(exm%==)
{
minx=min(minx,a[jishu]);
maxn=max(maxn,a[jishu]);
sum+=a[jishu];
}
exm=exm/;
jishu++;
} if((maxn-minx)>=x&&sum>=l&&sum<=r)
ans++;
}
printf("%d\n",ans);
return ;
}
C. Divisibility by Eight
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes.

Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-negative integer, doesn't have leading zeroes and is divisible by 8. After the removing, it is forbidden to rearrange the digits.

If a solution exists, you should print it.

Input

The single line of the input contains a non-negative integer n. The representation of number n doesn't contain any leading zeroes and its length doesn't exceed 100 digits.

Output

Print "NO" (without quotes), if there is no such way to remove some digits from number n.

Otherwise, print "YES" in the first line and the resulting number after removing digits from number n in the second line. The printed number must be divisible by 8.

If there are multiple possible answers, you may print any of them.

Examples
Input
3454
Output
YES
344
Input
10
Output
YES
0
Input
111111
Output
NO
题意:给你一个数 问是否能够 通过删除若干个数,并且剩下的数的相对位置不变 组成的数能够除尽8,若能则输出这个组成的数
题解:1000可以除尽8 所以只需要暴力考虑一位 两位 三位的组成.
 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
using namespace std;
char a[];
int main()
{
scanf("%s",a);
int len=strlen(a);
for(int i=;i<len;++i)
{
if(a[i]==''||a[i]==''){
printf("YES\n%c\n",a[i]);
return ;
}
}
for(int i=;i<len-;++i)
{
for(int k=i+;k<len;++k){
if(((a[i]-'')*+(a[k]-''))%==)
{
printf("YES\n%c%c\n",a[i],a[k]);
return ;
}
}
}
for(int i=;i<len-;++i)
{
for(int k=i+;k<len-;++k)
{
for(int l=k+;l<len;++l)
{
if(((a[i]-'')*+(a[k]-'')*+(a[l]-''))%==)
{
printf("YES\n%c%c%c\n",a[i],a[k],a[l]);
return ;
}
}
}
}
printf("NO\n");
return ;
}
D. Regular Bridge
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

An undirected graph is called k-regular, if the degrees of all its vertices are equal k. An edge of a connected graph is called a bridge, if after removing it the graph is being split into two connected components.

Build a connected undirected k-regular graph containing at least one bridge, or else state that such graph doesn't exist.

Input

The single line of the input contains integer k (1 ≤ k ≤ 100) — the required degree of the vertices of the regular graph.

Output

Print "NO" (without quotes), if such graph doesn't exist.

Otherwise, print "YES" in the first line and the description of any suitable graph in the next lines.

The description of the made graph must start with numbers n and m — the number of vertices and edges respectively.

Each of the next m lines must contain two integers, a and b (1 ≤ a, b ≤ n, a ≠ b), that mean that there is an edge connecting the vertices a and b. A graph shouldn't contain multiple edges and edges that lead from a vertex to itself. A graph must be connected, the degrees of all vertices of the graph must be equal k. At least one edge of the graph must be a bridge. You can print the edges of the graph in any order. You can print the ends of each edge in any order.

The constructed graph must contain at most 106 vertices and 106 edges (it is guaranteed that if at least one graph that meets the requirements exists, then there also exists the graph with at most 106 vertices and at most 106 edges).

Examples
Input
1
Output
YES
2 1
1 2
Note

In the sample from the statement there is a suitable graph consisting of two vertices, connected by a single edge.

题意:构造一个 每个点的度都为k,并且最少有一条割边的图

题解:

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
using namespace std;
int k;
int main()
{
scanf("%d",&k);
if(k==){
printf("YES\n");
printf("2 1\n1 2\n");
return ;
}
if(k%==){
printf("NO\n");
return ;
}
int n=k+;
printf("YES\n%d %d\n",n*,n*k);
for(int i=;i<=n;i++)
{
for(int j=i+;j<=n;j++)
{
if(i==&&j==n) continue;
if(j==i+&&(i%==)) continue;
printf("%d %d\n",i,j);
printf("%d %d\n",n+i,n+j);
}
}
printf("%d %d\n",,n+);
return ;
}

Codeforces Round #306 (Div. 2)A B C D 暴力 位/暴力 暴力 构造的更多相关文章

  1. 数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight

    题目传送门 /* 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 */ #include <cstdio> #include <a ...

  2. DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad

    题目传送门 /* DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : */ #include <cstdio> #include <iostream&g ...

  3. 水题 Codeforces Round #306 (Div. 2) A. Two Substrings

    题目传送门 /* 水题:遍历一边先找AB,再BA,再遍历一边先找BA,再AB,两种情况满足一种就YES */ #include <cstdio> #include <iostream ...

  4. Codeforces Round #306 (Div. 2) E. Brackets in Implications 构造

    E. Brackets in Implications Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

  5. Codeforces Round #306 (Div. 2) D. Regular Bridge 构造

    D. Regular Bridge Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...

  6. Codeforces Round #306 (Div. 2) C. Divisibility by Eight 暴力

    C. Divisibility by Eight Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...

  7. Codeforces Round #306 (Div. 2) B. Preparing Olympiad dfs

    B. Preparing Olympiad Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550 ...

  8. Codeforces Round #306 (Div. 2) A. Two Substrings 水题

    A. Two Substrings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...

  9. Codeforces Round #306 (Div. 2) 550A Two Substrings

    链接:http://codeforces.com/contest/550/problem/A 这是我第一次玩cf这种比赛,前面做了几场练习,觉得div2的前面几个还是比较水的. 所以看到这道题我果断觉 ...

  10. Codeforces Round #306 (Div. 2) A B C

    题目链接:http://codeforces.com/contest/550 A 暴力一发. 代码: #include <iostream> #include <stdio.h> ...

随机推荐

  1. spark重点知识

    1 scala 2 spark rdd 3 sprak core 4 性能优化 5 spark sql 6 spark streaming 掌握程度-精通的理解:

  2. mysql 5.5 zip配置安装

    1.解压2.创建option文件 --defaults-file=../my.ini [mysql] # 设置mysql客户端默认字符集 default-character-set=utf8 [mys ...

  3. Hyper-V虚拟机联网设置

    转自:http://www.3lian.com/edu/2012/12-22/50492.html Windows 8中内置的Hyper-V管理器可以说给许多人带来了惊喜!在Hyper-V管理器强大的 ...

  4. Scrum立会报告+燃尽图(十月十六日总第七次):总结工作经验,商讨未来策略

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2197 Scrum立会master:李文涛 一.小组介绍 组长:付佳 组员 ...

  5. 针对某一网站的UI进行分析

    本周课上教学通过对PM(项目经理)的学习,我了解到PM 对项目所有功能的把握, 特别是有关的UI内容.最差的UI, 体现了团队的组织架构:其次, 体现了产品的内部结构:最好, 体现了用户的自然需求. ...

  6. <<世界是数字的>>读书笔记

    <世界是数字的>这本书是大学职业规划老师介绍个我读的,从着本中我学到了很多. 第一章,计算机里有什么.这个问题可以从两方面来看:逻辑上或者说功能上的组成,即每一部分是什么.做什么.怎样做. ...

  7. 玩下软工项目,第一轮--全局Context的获取,SQLite的建立与增删改查,读取用户通话记录信息

    项目的Github地址:https://github.com/ggrcwxh/LastTime 采用基于git的多人协作开发模式 软件采用mvc设计模式,前端这么艺术的事我不太懂,交给斌豪同学去头疼了 ...

  8. bash循环语句

    1  )单分支if语句 if 测试条件 :then 如果满足条件就执行这里的代码 f 2)双分支的if语句 if  测试条件:then 如果满足条件就执行这里的代码 else 如果不满足条件就执行这里 ...

  9. 编写shell时,遇到let: not found错误及解决办法

    #!/bin/bashi=1sum=0while [ $i -le 100 ]do  let sum=sum+$i  let i++ done 在写一个简单的循环脚本时,报错 let: not fou ...

  10. 常用的Redis客户端的并发模型(转)

      伪代码模型 # get lock : timestamp = current Unix time + lock = SETNX lock.foo timestamp or (now() > ...