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. 3星|《科技投资新时代》:TMT行业资讯汇编

    科技投资新时代:TMT投资方法.趋势与热点聚焦 全书共6章,前4章是一些投资与分析的基本方法与技巧,第5章集中讲通信行业的现状与趋势,第6章讲大数据.物联网.全面屏等TMT行业热点. 总体来说数据.信 ...

  2. Mysql 单表主从同步

    先配主从同步,后将主库表老数据传输到从库 说明:api-server的数据库为主,其他harbor为从 1.master 配置文件更改 [mysqld] log-bin = mysql-bin ser ...

  3. 十大经典排序算法总结 (Python)

    作业部落:https://www.zybuluo.com/listenviolet/note/1399285 以上链接是自己在作业部落编辑的排序算法总结- Github: https://github ...

  4. 关于js中一个对象当做参数传递是按值传递还是按引用传递的个人看法

    在<JavaScript高级程序设计>这本书中有这样一段话:有很多开发人员错误的认为:在局部作用域中修改的对象会在全局作用域中反映出来,就说明参数是按引用传递的.换句话说,尼古拉认为当一个 ...

  5. Leftmost Digit(数学)

    Description Given a positive integer N, you should output the leftmost digit of N^N.   Input The inp ...

  6. 《Linux内核分析》学习总结与学习心得

    一.目录列表 第一周:计算机是如何工作的? http://www.cnblogs.com/dvew/p/5224866.html 第二周:操作系统是如何工作的? http://www.cnblogs. ...

  7. C# 未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序。

    在菜单 “项目”的最下面 工程属性 菜单,选择“生成”选项卡,将目标平台由“Amy CPU”或者“*64”改成“*86”.

  8. 项目Beta冲刺(团队)第二天

    1.昨天的困难 夜间模式实现的时候一点击开关就会出现app黑屏卡死的状态,recreate()方法实现有问题 服务器有点问题 2.今天解决的进度 成员 进度 陈家权 研究如何实现私信模块 赖晓连 最新 ...

  9. Hexo博客搭建全解

    [原创,转载请附网址:http://dongshuyan.top] 欢迎来到莫与的博客,第一篇记录了一下怎么写一篇博客,以方便之后写博客~ #从配置说起下载安装Git与Node.js略过 1.安装he ...

  10. 敏捷冲刺DAY6

    一. 每日会议 1. 照片 2. 昨日完成工作 3. 今日完成工作 4. 工作中遇到的困难 对于可视控件,是能进行设计的,但是对于不可视组件,比如AdoConnection怎么才能设计.但是我看del ...