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. find文本处理(locate)实例学习记录

    find文本处理(locate)实例学习记录 (一)按文件名称查找 按照文件名称查找是 find 最常见的用法,需要注意的是,搜索的文件名必须完全匹配,才能找到对应的文件. 1. 查找当前目录下所有 ...

  2. JVM之对象回收

    finalize /** *此代码演示了两点: *1.对象可以在被GC时自我拯救. *2.这种自救的机会只有一次,因为一个对象的finalize()方法最多只会被系统自动调用一次 */ public ...

  3. MyEclipse安装过程

    1.安装JDK并配置环境变量 下载地址: https://www.oracle.com/technetwork/java/javase/downloads/index.html ①点击download ...

  4. 对控制器类型“StudentController”的操作“Edit”的当前请求在下列操作方法之间不明确:

    "/"应用程序中的服务器错误. 对控制器类型"StudentController"的操作"Edit"的当前请求在下列操作方法之间不明确:类型 ...

  5. 9、MyBatis教程之多对一处理

    10.多对一处理 多对一的理解: 多个学生对应一个老师 如果对于学生这边,就是一个多对一的现象,即从学生这边关联一个老师! 1.创建数据库 CREATE TABLE `teacher` ( `id` ...

  6. MongoDB中“$”操作符表达式汇总

    MongoDB中"$"操作符表达式汇总 查询 比较操作 $eq 语法:{ : { $eq: } } 释义:匹配等于(=)指定值的文档 举例: 查询age = 20的文档: db.p ...

  7. 灵雀云Istio技术实践专题整理

    Istio技术实践专题(1) Service Mesh Istio 基本概念和架构基础 Istio被称作Kubernetes的最佳云原生拍档.从今天起,我们推出"Istio技术实践" ...

  8. Python数据分析入门(十四):数据分析中常用图

    折线图: 折线图用于显示数据在一个连续的时间间隔或者时间跨度上的变化,它的特点是反映事物随时间或有序类别而变化的趋势.示例图如下: 折线图应用场景: 折线图适合X轴是一个连续递增或递减的,对于没有规律 ...

  9. ELK7.11.2版本安装部署及ElastAlert告警相关配置

    文档开篇,我还是要说一遍,虽然我在文档内容中也会说好多遍,但是希望大家不要嫌我墨迹: 请多看官方文档,请多看命令行报错信息,请多看日志信息,很多时候它们比百度.比必应.比谷歌有用: 请不要嫌麻烦,打开 ...

  10. 【linux】驱动-11-gpio子系统

    目录 前言 11. gpio子系统 11.1 操作步骤 11.1.1 新版 API 操作流程 11.1.2 旧版 API 操作流程 11.2 设备树中使用gpio子系统 11.3 GPIO 子系统 A ...