A bracket(括号) sequence is a string containing only characters "(" and ")".A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+&q…
[链接]:CF [题意]: 给出n个字符串,保证只包含'('和')',求从中取2个字符串链接后形成正确的括号序列的方案数(每个串都可以重复使用)(像'()()'和'(())'这样的都是合法的,像')('和'('这样的是不合法的) 输入: 第一行一个整数n 第二行到第n+1行每行一个字符串 输出: 方案数 [分析]: 1.本来就正常的,只能和正常匹配的一起 2.本来就不正常匹配的,只能和不正常匹配的在一起 那么对于每一个串,我们处理出它还需要cnt1个'('和cnt2个')' 如果cnt1,cn2…
 Bracket Sequences Concatenation Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A bracket sequence is a string containing only characters "(" and ")". A regular bra…
ACM思维题训练集合 A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and &…
ACM思维题训练集合 A bracket sequence is a string, containing only characters "(", ")", "[" and "]". A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting…
明确一下  一个字符串有x左括号不匹配  和 另一个字符串有x个右括号不匹配  这俩是一定能够匹配的 脑子有点迷 emm... 所以统计就好了  统计x个左括号的有几个,x个右括号的有几个 然后 乘一下 如果一个串 同时存在左右括号都不匹配的情况 则忽略 因为这个串需要另外两个括号去匹配 不要忘了处理左右括号已经匹配的情况 #include <bits/stdc++.h> using namespace std; , INF = 0x7fffffff; typedef long long LL…
题目地址:24道CF的DIv2 CD题有兴趣可以做一下. ACM思维题训练集合 Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He ha…
ACM思维题训练集合 After passing a test, Vasya got himself a box of n candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself. This me…
ACM思维题训练集合 Desciption You've got an n × m pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture. A picture is a barcode if the following conditions are fulfilled: A…
ACM思维题训练集合 You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that: First we build by the array a an array s of partial sums, consisting of n elements. Element number…
ACM思维题训练集合 To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers…
ACM思维题训练集合 Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of n parts and to complete each part a player may probably need to complete some other ones. We know that the…
Nastya received a gift on New Year - a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right a…
既然补了就简单记录一下. 感觉还算有一点营养. 官方题解传送门:点我 A Commentary Boxes 对拆掉$n \mod m$个和新建$m - (n \mod m)$求个最小. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; int main() { ll n, m, a, b, r; scanf("…
Description A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and…
[#138 div 1 A. Bracket Sequence] [原题] A. Bracket Sequence time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A bracket sequence is a string, containing only characters "(", ")"…
A bracket sequence is a string, containing only characters "(", ")", "[" and "]". A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters…
题目链接:http://codeforces.com/problemset/problem/5/C 题目大意:给出一串字符串只有'('和')',求出符合括号匹配规则的最大字串长度及该长度的字串出现的次数.解题思路:设dp[i]为到i的最大括号匹配,我们每次遇到一个'('就将其下标存入栈中,每次遇到')'就取出当前栈中里它最近的'('下标即栈顶t.不能直接dp[i]=i-t+1,比如(()()())这样的例子就会出错,应为dp[i]=dp[i-1]+i-t+1. 代码 #include<bits/…
题目链接:http://codeforces.com/contest/918/problem/C 题目大意:给你一串字符串,其中有'('.')'.'?'三种字符'?'可以当成'('或者')'来用,问该字符串中有多少子串符合括号匹配的规则. 解题思路:根据括号匹配原始版进行改进,设置high和low分别表示未匹配左括号数的上限和下限,当遇到'('时low++,high++,遇到')'时low--,high--,遇到'?'时由于既可以表示'('又可以表示')',所以high++,low--. 原始版…
冲鸭,去刷题:http://codeforces.com/contest/1153/problem/C C. Serval and Parenthesis Sequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Serval soon said goodbye to Japari kindergarten, and b…
A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully sub…
codeforces 373 A - Efim and Strange Grade(算数模拟) 原题:Efim and Strange Grade 题意:给出一个n位的实型数,你可以选择t次在任意位进行四舍五入的进位,求最大结果. 解法:这道题一定不能忽略数位计算时本身带来的进位,如果我们要改变这个数的大小,一定是在最先的那个出现5以上的数字进行四舍五入,之后的t次允许我们多次四舍五入,如果自然进位则不消耗t. 最后一点,整数位的进位也是需要考虑的 #include <cstdio> #inc…
题目 传送门:QWQ 分析 洛谷题解里有一位大佬讲的很好. 就是先用栈预处理出可以匹配的左右括号在数组中设为1 其他为0 最后求一下最长连续1的数量. 代码 #include <bits/stdc++.h> using namespace std; ; char s[maxn]; int vis[maxn], Stack[maxn], top; int main(){ scanf(); ); ;i<=n;i++){ if(s[i]=='('){ Stack[++top]=i; } els…
题目地址 洛谷CF1272F Solution 首先题目中有两个括号串 \(s\) 和 \(t\) ,考虑先设计两维表示 \(s\) 匹配到的位置和 \(t\) 匹配到的位置. 接着根据 括号dp的一般套路:设计一维表示当前栈中的左括号数量 (ygt大佬喜欢形象地把其称为 "前缀和"),所以状态就出来了: \[f[i,j,k] \texttt{表示 s 匹配到 i , t 匹配到 j , 栈中有 k 个左括号,的最小新序列长度}\] 转移挺简单的,新序列要么增加一个 '(' , 要么增…
& -- 位运算之一,有0则0 原题链接 Problem - 1514B - Codeforces 题目 Example input 2 2 2 100000 20 output 4 226732710 题意 t个测试样例,在每个样例中 数组有n个数,数字范围[ 0, 2k - 1] 使得数组每个数&后,结果=0,并且这n个数的和要尽量大 输出有多少个这样的数组 解析 数组每个数&后,结果=0  -->每一位至少一个0 数要尽量大  -->只要这一位可以 != 0, 就…
Making Sequences is Fun Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 373B Description We'll define S(n) for positive integer n as follows: the number of the n's digits in the decimal…
题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0),先从1开始找到已经套好的娃娃层数, 其他是2次操作,还要减去k-1个娃娃是只要套上就可以 详细解释:http://blog.csdn.net/firstlucker/article/details/46671251 */ #include <cstdio> #include <algor…
ACM思维题训练集合 You are given k sequences of integers. The length of the i-th sequence equals to ni. You have to choose exactly two sequences i and j (i≠j) such that you can remove exactly one element in each of them in such a way that the sum of the chan…
题目链接:http://codeforces.com/problemset/problem/373/B 题目意思:给出w,m和k,需要找出从m开始,可以有多少个连续的数(m+1,m+2,...)(在添加(m+i)这个数到序列时,需要付出s(m+i) * k的代价,i = 1,2,...)满足不超过总代价w的长度. 可以列一个这样的方程: 一位数的个数*1*k + 两位数的个数*2*k + 三位数的个数*2*k + ... + n位数的个数*n*k = w 化简后得到: 一位数的个数*1 + 两位…
题目链接:900D  Unusual Sequences 题意: 给出两个数N,M.让你求数列(和为M,gcd为N)的个数. 题解: 首先,比较容易发现的是M%N如果不为零,那么一定不能构成这样的序列.那么可以设 k = M/N,则可以想象为用k个1来构成序列的个数,运用隔板原理可以求出k个1可以构成的序列总数为2^(k-1),但是这里面其实有不构成条件的(gcd>N)比方说6个相同的数(2,2,2)构成这样gcd就是2×N而不是N了.所以要减去这些数的情况,这样减的话发现不能用递归来做,要先记…