Educational Codeforces Round 101 (Rated for Div. 2)
A. Regular Bracket Sequence
题意:题目中给(和)还有?,其中?可以转换成为()中的任何一个,并且所给样例中只出现一次(),问能不能括号匹配
思路:直接看第一个和最后一个能不能匹配上,然后再看一下全部的长度是不是偶数个字符
想错:1)我一开始读错题,没有看到只出现一次的括号;
代码:


1 #include<iostream>
2 #include<algorithm>
3 #include<cstdio>
4 #include<cstring>
5 #include<cmath>
6 #include<queue>
7 using namespace std;
8 const long long int maxx=2e5+10;
9 int aa[maxx];
10 int bb[maxx];
11
12 int main(){
13 int t;
14 scanf("%d",&t);
15 getchar();
16 while(t--){
17 char s[200];
18 scanf("%s",&s);
19 int n=strlen(s);
20
21 if(n%2==1){
22 printf("NO\n");
23 }else{
24 int flag=0;
25 int i=0,j=n-1;
26 if((s[i]=='('&&s[j]==')')||(s[i]=='('&&s[j]=='?')||(s[i]=='?'&&s[j]=='?')||(s[i]=='?'&&s[j]==')')){
27
28 }else{
29 flag=1;
30 }
31 if(flag==1){
32 printf("NO\n");
33 }else{
34 printf("YES\n");
35 }
36 }
37 }
38 }
B. Red and Blue
题意:就是一组数a,然后染色成为红色r和蓝色b,记不清相对位置,给定红色中红色数出现的相对位置,蓝色也是,问f(a)=max(0,a1,(a1+a2),(a1+a2+a3),…,(a1+a2+a3+⋯+an+m)),这个数组a的最大值是多少
思路:就是找数组r和数组b已经确定,这两个构成的数组,最大的前缀和是多少,直接找到r和b分别最大的前缀和相加即可
代码:


1 #include<iostream>
2 #include<algorithm>
3 #include<cstdio>
4 #include<cstring>
5 #include<cmath>
6 #include<queue>
7 using namespace std;
8 const long long int maxx=2e5+10;
9 int aa[maxx];
10 int bb[maxx];
11
12 int main(){
13 int t;
14 scanf("%d",&t);
15 while(t--){
16 int a[250],b[250];
17 int n,m;
18 scanf("%d",&n);
19 int sum1=0,sum2=0;
20 int max1=0,max2=0;
21 for(int i=0;i<n;i++){
22 int num;
23 scanf("%d",&num);
24 sum1+=num;
25 max1=max(max1,sum1);
26 }
27 scanf("%d",&m);
28 for(int i=0;i<m;i++){
29 int num;
30 scanf("%d",&num);
31 sum2+=num;
32 max2=max(max2,sum2);
33 }
34 printf("%d\n",max1+max2);
35 printf("\n");
36 }
37 }
C. Building a Fence
题意: 给定一堆高度,然后去围栅栏,第一个和最后一个应该是必须挨着地面,其他围栏可以浮空,但是不能超过k-1
思路:依次处理每个围栏的区间,假设围栏所在区间最低为low,最高为high,则第一个围栏low = h[1], high = h[1] + k,第二个围栏low = max(low - k + 1, h[i]),因为每个区间需要有公共边,所以max里第二个值还需 + 1,high = min(high + k - 1, h[i] + 2 * k - 1),第一个区间最大值 + 围栏高度 - 1),因为围栏最多浮空k - 1,所以max里第一个值为地面高度 + k - 1 + k,因为每个区间需要有公共边,所以max里第二个值还需 - 1,以此类推见https://www.cnblogs.com/xiaopangpangdehome/p/14205266.html
想错:1)这个是dp区间的两边都要dp,这样一来就不是很好确定;2)不管是最大最小,一个是依赖与前面有公共边,另一个就是在高度为h[i]的高度上进行建筑;3)最低选最大值的时候肯定不浮空
代码:


1 #include<iostream>
2 #include<algorithm>
3 #include<cstdio>
4 #include<cstring>
5 #include<cmath>
6 #include<queue>
7 using namespace std;
8 const long long int maxx=2e5+10;
9 int main(){
10 int t;
11 scanf("%d",&t);
12 while(t--){
13 int a[maxx]={0},b[maxx]={0};
14 int n,k;
15 scanf("%d %d",&n,&k);
16 int flag=0;
17 for(int i=0;i<n;i++){
18 scanf("%d",&a[i]);
19 }
20 int low=0,high=0;
21 for(int i=0;i<n;i++){
22 if(i==0){
23 low=a[i];
24 high=a[i]+k;
25 }else{
26 low=max(low-k+1,a[i]);
27 high=min(high+k-1,a[i]+2*k-1);
28 }
29 if(high-k<a[i]||low>a[i]+k-1||high<low){
30 flag=1;
31 break;
32 }
33 }
34 if(low!=a[n-1]){
35 flag=1;
36 }
37 if(flag==0){
38 printf("YES\n");
39 }else{
40 printf("NO\n");
41 }
42
43 }
44 }
Educational Codeforces Round 101 (Rated for Div. 2)的更多相关文章
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- Educational Codeforces Round 39 (Rated for Div. 2) G
Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...
- Educational Codeforces Round 48 (Rated for Div. 2) CD题解
Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...
随机推荐
- Linux系统(Centos7)最新版本Docker简易(yum)安装步骤
Docker从1.13版本之后采用时间线的方式作为版本号,分为社区版CE和企业版EE. 社区版是免费提供给个人开发者和小型团体使用的,企业版会提供额外的收费服务,比如经过官方测试认证过的基础设施.容器 ...
- IPFS挖矿的成本有哪些?
IPFS作为区块链新贵,近来风头一时无量.截止3月9日,Filecoin以257亿的流通市值超越门罗币,稳居区块链流通排行榜. 无论什么投资,其门槛一定在成本.今天就和大家细说投资市面上常见实体矿机的 ...
- Ignatius and the Princess III HDU - 1028
题目传送门:https://vjudge.net/problem/HDU-1028 思路:整数拆分构造母函数的模板题 1 //#include<bits/stdc++.h> 2 #incl ...
- Mysql之索引选择及优化
索引模型 哈希表 适用于只有等值查询的场景,Memory引擎默认索引 InnoDB支持自适应哈希索引,不可干预,由引擎自行决定是否创建 有序数组:在等值查询和范围查询场景中的性能都非常优秀,但插入和删 ...
- 敏捷史话(十三):我被 Facebook 解雇了——Kent Beck
2011年,Kent Beck 加入了 Facebook .那时候的他已年过半百,几十年的经验让他自认为非常了解软件行业.在 Facebook 的新手训练营期间,Kent 开始意识到,Facebook ...
- 深度学习---1cycle策略:实践中的学习率设定应该是先增再降
深度学习---1cycle策略:实践中的学习率设定应该是先增再降 本文转载自机器之心Pro,以作为该段时间的学习记录 深度模型中的学习率及其相关参数是最重要也是最难控制的超参数,本文将介绍 Lesli ...
- c# 输出一个数组
关于C#输出一个数组最普遍的方法就是用for 循环语句写 如: int[] a = new int[10];for (int i = 0; i < a.Length; i++) { a[i] = ...
- 【原创】【基础】一文搞懂严蔚敏数据结构SqList &L和SqList L、ElemType &e和ElemType e
旁白 最近小渔夫在看严蔚敏.李冬梅<数据结构 c语言版>(第2版),学到第二章顺序表的实现时,看到函数参数一会是SqList &L.一会又是SqList L.一会ElemType ...
- 基于MATLAB的手写公式识别(2)
基于MATLAB的手写公式识别 图像的预处理(除去噪声.得到后续定位分割所需的信息.) 预处理其本质就是去除不需要的噪声信息,得到后续定位分割所需要的图像信息.图像信息在采集的过程中由于天气环境的影响 ...
- 963. Minimum Area Rectangle II
Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from these ...