Codeforces Round #306 (Div. 2)
发布日期:2021-09-19 06:09:12 浏览次数:21 分类:技术文章

本文共 5596 字,大约阅读时间需要 18 分钟。

最近是怎么了,老是掉分,sad = =.......

明明都会做,但一到比赛时,就没有想法了。。。估计是太困了吧。。。

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.

Sample test(s)
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"就可以了,还是要分别都要两个,事后想想,这个愚蠢的问题。。。然后回过头看,wa~,完了,又要掉分了。。。

想法呢:

就是for4遍,首先第一遍是为了先找出AB有没有,然后for第二遍找出BA,记得把AB所在的位置要标记上;

然后如果上面找到两种字符串的话,那么就不用进行下面的语句了,但是没有找到,那么就要for先找出BA,然后就再去找AB,大致与上面找的方法相同。

#include
#include
#include
#include
#include
using namespace std;#define maxn 111111map
mp;char a[maxn];int mp1[maxn],mp2[maxn];int main(){ scanf("%s",a); int len=strlen(a); int i,j,k,l; bool f1,f2; f1=f2=false; for(i=0;i

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 nlrx (1 ≤ n ≤ 151 ≤ l ≤ r ≤ 1091 ≤ 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.

Sample test(s)
input
3 5 6 11 2 3
output
2
input
4 40 50 1010 20 30 25
output
2
input
5 25 35 1010 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.

这道题我一开始没有想出来,后来看别人的想法做的,就是一个dfs。

题意就是给你限定了一个范围区间[l,r]; 然后你可以选n门课中的任意门然后要使它们的难度系数之和在这个区间范围内,然后在你所选的课中找出最大值max,最小值min,然后它们两个的差值要大于等于x才行,然后问你总共有几种选课的方法。

#include
#include
#include
#include
using namespace std;#define maxn 22#define inf 99999999int a[maxn],l,r,x,n;int num=0;void dfs(int cur,int sum,int ma,int mi,int cnt){ if(sum>r) return; if(ma
a[cur]) mi=a[cur]; if(sum>=l&&sum<=r&&(ma-mi>=x)&&cnt>=2){ num++; //return 注意了,这里并不用加return,因为我们这里并不需要返回,因为我们要做的就是让它不撞南墙不回头的去搜索!!! } for(int i=cur+1;i

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.

Sample test(s)
input
3454
output
YES344
input
10
output
YES0
input
111111
output
NO
这道题我是找规律的,首先我发现后两位数是有重复的,比如说从0~100与200~300的后两位是重复的,从100~200与300~400的后两位是重复的,所以我们可以对后两位进行判断。

代码有点挫,先贴上来,明天再整理下。

#include
#include
#include
#include
using namespace std;#define maxn 111char a[maxn];int mp[33];int main(){ scanf("%s",a); int len=strlen(a); for(int i=0;i
=2&&flag) {puts("YES"); printf("112\n");return 0;} for(int i=0;i
=2&&flag) {puts("YES"); printf("%d44\n",tx);return 0;} flag=false; for(int i=0;i
感觉就像是一个暴暴力~~~

还有每次必说的——加油!

转载地址:https://blog.csdn.net/ACMer_hades/article/details/46404171 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:hdu(1166)——敌兵布阵(更新节点,区间求和)
下一篇:hdu(1394)——Minimum Inversion Number

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2024年03月08日 17时08分00秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

php tire树,Immutable.js源码之List 类型的详细解析(附示例) 2019-04-21
matlab转差频率控制,转差频率控制的异步电机调速系统的研究 2019-04-21
oracle错误1327,Oracle中的PGA监控报警分析(r11笔记第97天) 2019-04-21
php函数内的循环,PHP 循环列出目录内容的函数代码 2019-04-21
oracle树状排序,Oracle树状结构查询 2019-04-21
深度linux内核升级,深度操作系统 2020.11.11 更新发布:内核升级 2019-04-21
sql 拆解函数_SQL入门50题详解(含知识点讲解及代码运行步骤拆解) 2019-04-21
java和python交互 jni_Python基于pyjnius库实现访问java类 2019-04-21
macbook pro 卸载mysql_MacBook Pro全新重装OS X Yosemite 2019-04-21
已达到计算机的连接数最大值无法再同此远程计算机连接_电脑远程访问已达到计算机的连接数最大值怎么办?解决方法很简单... 2019-04-21
mysql表名长度_JavaWeb之MySQL(一) 2019-04-21
mysql服务器语法_Mysql语法 2019-04-21
pdf 模版 汉字和数字_《吉林大学珠海学院毕业论文(设计)模板》(汉字标题版) .pdf... 2019-04-21
python bottle部署_nginx+uwsgi+bottle python服务器部署 2019-04-21
python双击py一闪_Python脚本在双击.py时无法正常运行 2019-04-21
redis logfile为空_关于Redis(二) 2019-04-21
mysql 设计两个主键都不可重复_程序员面试备战篇:18个经典MySQL面试专题解析(干货分享答案)... 2019-04-21
下列关于python2.x和3.x的区别说法正确_Python 2.x和Python 3.x版本有哪些区别?【面试题详解】... 2019-04-21
git更换_git命令 2019-04-21
hp-ux 查看系统负载_Linux性能调优 | 平均负载的理解和分析 2019-04-21