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> ...
随机推荐
- openvpn部署
原文发表于cu:2016-03-29 参考文档: 安装:http://qicheng0211.blog.51cto.com/3958621/1575273 安装:http://www.ipython. ...
- nordic-mesh中应用的代码实现
nordic-mesh中应用的代码实现 Nordic-Mesh遵循SIG-Mesh-Profile中的mesh定义,实现了element.model等概念. 一个应用中包含一个或多个element,e ...
- [咸恩静][Coffee House]
歌词来源:http://music.163.com/#/song?id=5400159 하루의 시작은 향긋한 커피 [ha-lu-e xi-ja-geun hyang-geu-Tan Keo-Pi] ...
- 亚马逊AWS业务副总裁:如何在基础设施上降成本
腾讯科技 林靖东 11月17日编译 亚马逊Amazon Web Services业务的副总裁.著名工程师詹姆斯汉密尔顿(James Hamilton)在AWS re:Invent大会上解释了公司是如何 ...
- JavaScript变态题目
刚才发现的一些变态的 JavaScript 题目,做了一下,只对了一半,特此发到园子里,和友友们分享一下.这些题目都是针对 Ecmascript 第三版的,原题里面全部都是选择题,有备选答案,这里我把 ...
- vue之指令篇 ps简单的对比angular
这两天在开始vue的大型项目,发现和ng还是有许多不同,这里对比下两者的指令系统 难度系数:ng的指令难度大于vue:至少vue上暂时没发现@&=:require,compile,precom ...
- 关于css文字的扩展
1.不换行: .title{ white-space:nowrap; text-overflow:ellipsis; } 2.超出变三点 .title{ white-space:nowrap; tex ...
- 《C》数据类型
- 四则运算3+psp0
题目要求: 1.程序可以判断用户的输入答案是否正确,如果错误,给出正确答案,如果正确,给出提示. 2.程序可以处理四种运算的混合算式. 3.要求两人合作分析,合作编程,单独撰写博客. 团队成员:张绍佳 ...
- struts2文件上传突破2M限制
struts配置文件 <action name="upload" class="strutsFileUpload"> <result name ...