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> ...
随机推荐
- How to pass an Amazon account review
Have you ever sold products on Amazon? How about sold so much within the first week that amazon deci ...
- 20181113-7 Beta阶段第1周/共2周 Scrum立会报告+燃尽图 04
作业要求:[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2386] 版本控制:[https://git.coding.net/lglr2 ...
- 软件工程-东北师大站-第六次作业PSP
1.本周PSP 2.本周进度条 3.本周累计进度图 代码累计折线图 博文字数累计折线图 4.本周PSP饼状图
- FIsherman丶Team
小组成员:郝恒杰,洪佳兴,张子祥 组长:郝恒杰 项目:Fisher Job(渔夫兼职) 简介: 我们的产品渔夫兼职是为了解决大学生兼职群体 的痛苦,他们需要一个好的渠道去找一个让自己满意的兼职,但是现 ...
- 软件工程 - 第二十次作业 Alpha 事后诸葛亮(团队)
Alpha 事后诸葛亮(团队) 组长本次作业链接:https://www.cnblogs.com/dawnduck/p/10056026.html 现代软件工程 项目Postmortem 设想和目标 ...
- C++ Primer Plus学习:第九章
C++第九章:内存模型与名称空间 C++在内存中存储数据方面提供了多种选择.可直接选择保留在内存中的时间长度(存储持续性)以及程序哪一部分可以访问数据(作用域和链接)等. 单独编译 程序分为三个部分: ...
- Swift-switch使用注意点
1.swift后面的()可以省略 2.case后面的额break可以省略 3.如果想产生case穿透使用fallthrough 4.case后面可以判断多个条件","分割 5.sw ...
- java 数据结构与算法 之查找法
一.二分查找法 二分查找就是将查找的键和子数组的中间键作比较,如果被查找的键小于中间键,就在左子数组继续查找:如果大于中间键,就在右子数组中查找,否则中间键就是要找的元素. @Test public ...
- BER-TLV数据结构【转】
转自:https://www.cnblogs.com/SCPlatform/p/5076935.html 为了便于后文的引用说明,先列出一段TLV结构的数据: [6F] 4D │ ├─[84] 07 ...
- jquery实现可编辑的下拉框( input + select )
HTML: <input id="inputModel" /> <select name="EngineModel" size="1 ...