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)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  4. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  5. 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 ...

  6. 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 ...

  7. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  8. 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 < ...

  9. Educational Codeforces Round 48 (Rated for Div. 2) CD题解

    Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...

随机推荐

  1. CSS浮动布局带来的高度塌陷以及其解决办法

    1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="U ...

  2. 【odoo14】第二十三章、管理邮件

    邮件集成是odoo最重要的特性.我们可以通过odoo收发邮件.我们甚至可以管理业务文档上的电子邮件,如潜在客户.销售订单和项目.本章,我们将探讨在odoo中处理邮件的方式. 配置邮件服务器 管理文档中 ...

  3. 什么是SSR SSR有什么用 如何使用使用SSR

    什么是SSR 以下信息来自维基百科: Shadowsocks(简称SS)是一种基于Socks5代理方式的加密传输协议,也可以指实现这个协议的各种开发包.当前包使用Python.C.C++.C#.Go语 ...

  4. [题解] [NOI Online 2021 入门组 T3] 重力球

    题目大意 在一个 \(n\times n\) 的矩形中,题目会给出 \(m\) 个障碍物.有两个小球,你可以选定四个方向(上下左右)的其中一个,小球会朝着这四个方向一直滚动,直到遇到障碍物或是矩形的边 ...

  5. 面试准备——计算机网络(http)

    一.各种协议与HTTP协议之间的关系 二.URI(统一资源标识符) URI用字符串标识某一互联网资源. URI的格式: 协议方案名:指定访问资源时使用的协议类型. 登录信息(认证):可选,指定用户名和 ...

  6. ASP.NET网页开发基础(7)

    整理了一点的小知识点: 1.ASP.NET网页扩展名:    .asax 全局应用程序类的扩展名     .xml 访问网页时的扩展名     .htm     .ascx Web用户控件的扩展名   ...

  7. Kotlin编写Processing程序(使用函数式编程思维和面向接口方式)

    写一例Kotlin编写的Processing程序,充分调用函数式编程思维和面向接口的编程思维,供自己和读者参考学习. 初衷 想要实现一行行的文字排版功能,每一行作为一个单位,可制定显示的位置.大小.文 ...

  8. Markdown排版介绍

    如何排版章节 Markdown: 大标题 ========== 小标题 ---------- # 一级标题 ## 二级标题 ### 三级标题 #### 四级标题 例如 三级 和四级 发布后的效果: 三 ...

  9. Qt中检查槽函数connect是否正确

    环境:VS2017+Qt插件 一般情况下VS+QT环境下运行的QT程序输出信息需要在调试模式的输出栏可以看到,由于太多信息所以导致查看不方便(当然也可以在筛选选项中筛选信息). 有更方便查看输出信息的 ...

  10. mysql 遇到的问题

    1) 客户端(Navicat)远程登录操作再遇问题1142-create command denied to user×××的解决GRANT SELECT,INSERT,UPDATE,DELETE,C ...