题目大意:一个字符串只含有? ( ),?可以变成 ) 或者 ( ,将字符串中所有的?变成) 或者 ( 使得字符串合法. 合法就是让括号配对,并且不可以提前结束比如:()()这样是不合法的. 题解:既然不能提前结束,那第一个字符必须和最后一个匹配,所以我们只要关注从2~n-1就可以了. 我们可以正着扫一遍,在任何一个位置")"的数目必须小于等于"("+"?". 然后再倒着扫一遍,同样地,在任何位置的"("的数目必须小于等于&qu…
冲鸭,去刷题: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…
题目地址:CF1153C Serval and Parenthesis Sequence 思路:贪心 如果有解,那么 \(s_0 = (\) && \(s_{n-1} = )\) && \(n % 2 = 0\) . 如果有解,那么 \(s_1\) ~ \(s_{n-2}\) 为一个合法的括号序列. 那么已知的 \((\) 和 \()\) 个数不能超过一半 接下来贪心:如果有解,那么一定有一组解是把 \(?\) 中左边一部分填成 \((\) ,右边一部分填成 \()\) ,…
Serval and Parenthesis Sequence 题目链接(点击) Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is…
题目链接:http://codeforces.com/contest/1153/problem/C 题意:给定由'(',')','?'组成的字符串,问是否能将其中的?全部换成'(‘,’)'使得字符串的任意非空真字串不构成正确的括号表达式,而整个字符串构成括号表达式,其中正确的括号表达式是指通过插入'1','+'能构成算术式. 思路:我们记'('为-1,')'为1,显然所有字串应满足前面的和<0,字串等于0的话就不满足字串不构成正确的括号表达式了,且整个字符串的和=0(题目可能出现'((((??'…
括号正确匹配问题,应该不难 #include <iostream> #include <cstring> #include <string> #include <map> #include <set> #include <algorithm> #include <fstream> #include <cstdio> #include <cmath> #include <stack> #i…
Increasing Sequence CodeForces - 11A 很简单的贪心.由于不能减少元素,只能增加,过程只能是从左到右一个个看过去,看到一个小于等于左边的数的数就把它加到比左边大,并记录加的次数. 错误记录: 但是很容易错...以前错了4次..过几个月来再做还是不能1A... 比如下面这个有很明显错误的程序 #include<cstdio> int n,d,last,now,ans; int main() { int i; scanf("%d%d",&…
Almost Regular Bracket Sequence CodeForces - 1095E You are given a bracket sequence ss consisting of nn opening '(' and closing ')' brackets. A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expressio…
D - The Child and Sequence 思路: 因为有区间取模操作所以没法用标记下传: 我们发现,当一个数小于要取模的值时就可以放弃: 凭借这个来减少更新线段树的次数: 来,上代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 100005 #define ll lo…
C. Vasily the Bear and Sequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasily the bear has got a sequence of positive integers a1, a2, ..., *a**n*. Vasily the Bear wants to write o…
大意: 构造一个[1,2,...n]的排列, 使得前缀积模n为[0,1,...,n-1]的排列 这种构造都好巧妙啊, 大概翻一下官方题解好了 对于所有>=6的合数$n$, 有$(n-1)! \equiv 0 \space (mod \space n)$, 一定不成立 对于素数可以构造$[1,\frac{2}{1},\frac{3}{2},\frac{4}{3},...,\frac{n-1}{n-2},n]$, 或者构造$[1,g,g^{-2},g^3,g^{-4},...,n]$, $g$为$n…
Codeforces Round #551 (Div. 2) 算是放弃颓废决定好好打比赛好好刷题的开始吧 A. Serval and Bus 处理每个巴士最早到站且大于t的时间 #include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ')…
cf-551-div2-D C. Serval and Parenthesis Sequence 题意:给定由'(',')','?'组成的字符串,问是否能将其中的?全部换成'(‘,’)'使得字符串的任意非空真字串不构成正确的括号表达式,而整个字符串构成括号表达式,其中正确的括号表达式是指通过插入'1','+'能构成算术式. 思路:我们记'('为-1,')'为1,显然所有字串应满足前面的和<0,字串等于0的话就不满足字串不构成正确的括号表达式了,且整个字符串的和=0(题目可能出现'((((??'这…
A. Serval and Bus 算出每辆车会在什么时候上车, 取min即可 #include<cstdio> #include<algorithm> #include<cstring> #include<queue> #include<iostream> #define ll long long #define M 101 #define mmp make_pair using namespace std; int read() { int…
突然发现上一场没有写,那就补补吧 本来这场应该5题的,结果一念之差E fail了 A. Serval and Bus 基本数学不解释,假如你没有+1 -1真的不好意思见人了 #include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> using namespace std; con…
题目链接:http://codeforces.com/contest/1153 A .Serval and Bus pro:给出n种公交车的首班车时间和两班车之间的时间间隔,找t时间以后的第一辆车是第几种车 sol:对于每种车,找到t时间以后的第一班车的时间,计算这个时间和t的差距,然后找离t最近的 暴力 #include "bits/stdc++.h" using namespace std; ; const int INF = 0x3f3f3f3f; int ans, k = IN…
原题链接 http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 Description Bobo has a balanced parenthesis sequence P=p1 p2…pn of length n and q questions. The i-th question is whether P remains balanced after pai and pbi  swapped. Note that questions ar…
1809: Parenthesis Description Bobo has a balanced parenthesis sequence P=p1 p2…pn of length n and q questions. The i-th question is whether P remains balanced after pai and pbi  swapped. Note that questions are individual so that they have no affect…
Problem G: Parenthesis Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 398  Solved: 75[Submit][Status][Web Board] Description Bobo has a balanced parenthesis sequence P=p1 p2…pn of length n and q questions. The i-th question is whether P remains balan…
Parenthesis Problem Description: Bobo has a balanced parenthesis sequence P=p1 p2-pn of length n and q questions. The i-th question is whether P remains balanced after pai and pbi swapped. Note that questions are individual so that they have no affec…
Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of length n and q questions. The i-th question is whether P remains balanced after p ai and p bi  swapped. Note that questions are individual so that they have no affect on others. Parenthesis se…
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1809 Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of length n and q questions. The i-th question is whether P remains balanced after p ai and p bi  swapped. Note that questions are ind…
1809: Parenthesis Time Limit: 5 Sec     Memory Limit: 128 Mb     Submitted: 2291     Solved: 622 Description Bobo has a balanced parenthesis sequence P=p1 p2…pn of length n and q questions. The i-th question is whether P remains balanced after pai an…
1809: Parenthesis Submit Description Bobo has a balanced parenthesis sequence P=p1 p2…pn of length n and q questions. The i-th question is whether P remains balanced after pai and pbi  swapped. Note that questions are individual so that they have no…
2016湖南省赛----G - Parenthesis (括号匹配)   Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of length n and q questions. The i-th question is whether P remains balanced after p ai and p bi  swapped. Note that questions are individual so that they hav…
A - Infinite Sequence  CodeForces - 622A 题目大意:给你一个这样的数列1,1,2,1,2,3,1,2,3,4,1,2,3,4,5....就是从1~n排列(n++).最后问你第n个位置是什么数字. 思路:如果你花点时间列数列的话会发现,1~n的最后一位对应的位置是1~n的和,那我们就大胆使用二分进行搜索这位数. #include<iostream> #include<algorithm> #include<cstdio> #incl…
1809: Parenthesis Submit Page     Summary    Time Limit: 5 Sec     Memory Limit: 128 Mb     Submitted: 1500     Solved: 398 Description Bobo has a balanced parenthesis sequence P=p1 p2…pn of length n and q questions. The i-th question is whether P re…
Description Bobo has a balanced parenthesis sequence P=p1 p2…pn of length n and q questions. The i-th question is whether P remains balanced after pai and pbi  swapped. Note that questions are individual so that they have no affect on others. Parenth…
Least Cost Bracket Sequence CodeForces - 3D 题目描述 This is yet another problem on regular bracket sequences. A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example,…
  G - Parenthesis Time Limit:5000MS     Memory Limit:131072KB     64bit IO Format:%lld & %llu Description Bobo has a balanced parenthesis sequence P=p 1 p 2-p n of length n and q questions. The i-th question is whether P remains balanced after p ai a…