Codeforces Round #306 (Div. 2)A B C D 暴力 位/暴力 暴力 构造
2 seconds
256 megabytes
standard input
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).
The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
ABA
NO
BACFAB
YES
AXBYBXA
NO
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 ;
}
2 seconds
256 megabytes
standard input
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.
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.
Print the number of ways to choose a suitable problemset for the contest.
3 5 6 1
1 2 3
2
4 40 50 10
10 20 30 25
2
5 25 35 10
10 10 20 10 20
6
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 ;
}
2 seconds
256 megabytes
standard input
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.
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.
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.
3454
YES
344
10
YES
0
111111
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 ;
}
2 seconds
256 megabytes
standard input
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.
The single line of the input contains integer k (1 ≤ k ≤ 100) — the required degree of the vertices of the regular graph.
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).
1
YES
2 1
1 2
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 暴力 位/暴力 暴力 构造的更多相关文章
- 数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight
		
题目传送门 /* 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 */ #include <cstdio> #include <a ...
 - DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad
		
题目传送门 /* DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : */ #include <cstdio> #include <iostream&g ...
 - 水题 Codeforces Round #306 (Div. 2) A. Two Substrings
		
题目传送门 /* 水题:遍历一边先找AB,再BA,再遍历一边先找BA,再AB,两种情况满足一种就YES */ #include <cstdio> #include <iostream ...
 - 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 ...
 - 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 ...
 - 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/ ...
 - 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 ...
 - 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 ...
 - Codeforces Round #306 (Div. 2)  550A  Two Substrings
		
链接:http://codeforces.com/contest/550/problem/A 这是我第一次玩cf这种比赛,前面做了几场练习,觉得div2的前面几个还是比较水的. 所以看到这道题我果断觉 ...
 - Codeforces Round #306 (Div. 2) A B C
		
题目链接:http://codeforces.com/contest/550 A 暴力一发. 代码: #include <iostream> #include <stdio.h> ...
 
随机推荐
- datax 执行流程分析
			
https://www.jianshu.com/nb/29319571 https://www.jianshu.com/p/b10fbdee7e56
 - CSP201604-2:俄罗斯方块
			
引言:CSP(http://www.cspro.org/lead/application/ccf/login.jsp)是由中国计算机学会(CCF)发起的"计算机职业资格认证"考试, ...
 - Windows下遍历某目录下的文件
			
需求:要求遍历某个目录下的所有文件,文件夹 之前遇到过一些参考程序,其中有一种方法只能遍历 FAT32 格式的目录, 无法遍历NTFS的目录.
 - 王者荣耀交流协会第四次Scrum立会
			
会议时间:2017年10月23号 18:00-18:28,时长28分钟. 会议地点:二食堂一楼第四个档口对着的靠路边的桌子. 立会内容: 1.小组成员汇报今日工作: 2.关于折线图与饼状图生成问题 ...
 - 欢迎来怼—第三次Scrum会议
			
一.会议成员 队名:欢迎来怼队长:田继平队员:李圆圆,葛美义,王伟东,姜珊,邵朔,冉华小组照片: 二.会议时间 2017年10月15日 17:15-17:41 总用时26min 三.会议地点 ...
 - HDU 5265 pog loves szh II 二分
			
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5265 bc(中文):http://bestcoder.hdu.edu.cn/contests ...
 - HttpWebRequest下载文件,乱码问题解决方案
			
写在前面 今天之所以会总结HttpWebRequest下载文件,主要是因为在使用该类下载文件的时候,有些地方需要注意一下,在实际的项目中遇到过这种问题,觉得还是有必要总结一下的.在下载文件时,最常见的 ...
 - Spring学习(七)——增强类
			
Spring 切点 什么是切点?切点(Pointcut),每个程序类都拥有多个连接点,如一个拥有两个方法的类,这两个方法都是连接点,即连接点是程序类中客观存在的事物.但在这为数从多的连接点中,如何定位 ...
 - 使用Logstash同步数据至Elasticsearch,Spring Boot中集成Elasticsearch实现搜索
			
安装logstash.同步数据至ElasticSearch 为什么使用logstash来同步,CSDN上有一篇文章简要的分析了以下几种同步工具的优缺点:https://blog.csdn.net/la ...
 - MQTT协议-----订阅
			
MQTT协议笔记之订阅 http://www.blogjava.net/yongboy/archive/2014/04/12/412351.html MQTT - chszs的专栏 h ...