设为首页 加入收藏

TOP

Codeforces Round #306 (Div. 2) (ABCE题解)(一)
2015-11-21 00:59:49 来源: 作者: 【 】 浏览:5
Tags:Codeforces Round #306 Div. ABCE 题解

?



A. Two Substrings time limit per test 2 seconds memory limit per test 256 megabytes

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

?

题目分析:暴力扫4次,第一二次先扫AB后扫BA,第三四次先扫BA后扫AB,注意这组样例ABACCCAB

?

?

#include 
  
   
#include 
   
     #include 
    
      using namespace std; int const MAX = 1e5 + 5; char s1[MAX], s2[MAX]; int main() { scanf(%s, s1); memcpy(s2, s1, sizeof(s1)); int len = strlen(s1); bool f1 = false; bool f2 = false; for(int i = 0; i < len; i++) { if(s1[i] == 'A' && s1[i + 1] == 'B') { f1 = true; s1[i] = s1[i + 1] = '*'; break; } } for(int i = 0; i < len; i++) if(s1[i] == 'B' && s1[i + 1] == 'A') f2 = true; if(f1 && f2) { printf(YES ); return 0; } f1 = f2 = false; for(int i = 0; i < len; i++) { if(s2[i] == 'B' && s2[i + 1] == 'A') { f1 = true; s2[i] = s2[i + 1] = '*'; break; } } for(int i = 0; i < len; i++) if(s2[i] == 'A' && s2[i + 1] == 'B') f2 = true; if(f1 && f2) { printf(YES ); return 0; } printf(NO ); }
    
   
  

?

?

?

B. Preparing Olympiad time limit per test 2 seconds memory limit per test 256 megabytes

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.

Sample test(s) 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个问题每个难度为ci,要选一些题出来,要求这些题的总难度不超过r且不小于l,且难度最大的和难度最小的差不能小于x,问有多少种选法

?

题目分析:n等于15,随便搞,我是直接深搜,简洁明了

?

?

#include 
  
   
#include 
   
     #include 
    
      using namespace std; int const INF = 0x3fffffff; int n, l, r, x; int c[20]; int ans; void DFS(int idx, int ma, int mi, int sum) //第几个题,当前最大,当前最小,难度总和 { if(idx == n + 1) return; if(sum <= r && sum >= l && x <= ma - mi && idx == n) ans ++; DFS(idx + 1, max(ma, c[idx]), min(mi, c[idx]), sum + c[idx]); //选第idx个 DFS(idx + 1, ma, mi, sum); //不选第idx个 return; } int main() { scanf(%d %d %d %d, &n, &l, &r, &x); for(int i = 0; i < n; i++) scanf(%d, &c[i]); ans = 0; DFS(0, 0, INF, 0); printf(%d , ans); }
    
   
  

?

?



C. Divisibility by Eight time limit per test 2 seconds memory limit per test 256 megabytes

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 c

首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ3623:Best Cow Line, Gold(后.. 下一篇C Language Study - 函数指针的使..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: