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. 想了解FlinkX-Oracle Logminer?那就不要错过这篇文章

    FlinkX-Oracle Logminer模块是FlinkX基于Logminer对Oracle重做日志进行实时采集分析,可对Oracle进行实时同步也可以通过指定SCN或者时间戳从某个节点进行同步, ...

  2. 在ASP.NET Core中用HttpClient(四)——提高性能和优化内存

    到目前为止,我们一直在使用字符串创建请求体,并读取响应的内容.但是我们可以通过使用流提高性能和优化内存.因此,在本文中,我们将学习如何在请求和响应中使用HttpClient流. 什么是流 流是以文件. ...

  3. springBoot高级:自动配置分析,事件监听,启动流程分析,监控,部署

    知识点梳理 课堂讲义 02-SpringBoot自动配置-@Conditional使用 Condition是Spring4.0后引入的条件化配置接口,通过实现Condition接口可以完成有条件的加载 ...

  4. Edge 浏览器开发工具新增了 3D 视图,你尝试了吗?

    在使用开发者工具的时候,无意间发现了一个3D面板,如下: 仔细想想,这应该是之前 Firefox 的特性啊,不过后来去掉了,说是太难维护,没想到 Edge 也添加了这个特性. 使用该特性,你可以完成如 ...

  5. SpingCloud Alibaba实战(1:微服务与SpringCloud Alibaba)

    1.什么是微服务? 微服务可谓是这几年比较热门的技术,从2017开始逐渐爆火,逐渐大大小小的公司纷纷将微服务技术引入并在实际业务中落地. 微服务的概念最早是在2014年由Martin Fowler和J ...

  6. Oracle 存储结构

    数据库是存储数据的容器,它的主要功能是保存和共享数据. oracle数据库的存储结构可以分为逻辑存储结构和物理存储结构,对于这两种存储结构,oracle是分别进行管理的. 逻辑存储结构:oracle内 ...

  7. C. 【例题3】单词替换

    C . [ 例 题 3 ] 单 词 替 换 解析 可以一个个单词读取,输入完之后, 讲整个句子的每个单词遍历一次, 如果这个单词是与单词 a a a相同的话, 就输出 b b b, 否则输出这个单词 ...

  8. 华为云PB级数据库GaussDB(for Redis)揭秘第七期:高斯Redis与强一致

    摘要:在KV数据库领域,"强一致性"不仅是一个技术名词,它更是业务与运维的重要需求. 清明刚过,五一假期就要来了.大好春光,不如去婺源看油菜花吧!小云迅速打开APP刷出余票2张,赶 ...

  9. Anacoda下报错conda command not found 以及TypeError: __new__() got an unexpected keyword argument 'serialized_options'

    在anacoda安装完成后,执行conda list命令,显示command not found 解决方法: 对于anaconda 2  , 输入export PATH=~/anaconda2/bin ...

  10. Linux保护机制和绕过方式

    Linux保护机制和绕过方式 CANNARY(栈保护) ​ 栈溢出保护是一种缓冲区溢出攻击缓解手段,当函数存在缓冲区溢出攻击漏洞时,攻击者可以覆盖栈上的返回地址来让shellcode能够得到执行.用C ...