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 ...
随机推荐
- All I know about A/B Test (1) : 均值型指标与比值(率)型指标的计算区别
因为最近在找实习,所以打算把自己之前学过的关数据分析的知识总结(复习)一下.在总结A/B test时,我发现中文互联网中关于A/B test的总结已经很多了,但是对于均值型指标和比值(率)型指标在设计 ...
- C# 输出一个字符串的前缀、后缀和它的子串(信息内容安全 实验一)
一.什么是前后缀 字符串的前缀:符号串左部的任意子串(或者说是字符串的任意首部) 字符串的后缀:符号串右部的任意子串(或者说是字符串的任意尾部) 举例:比如 101110 它的前缀就是空串.1.10. ...
- 走进springboot
SpringBoot基础 核心思想---自动装配---约定大于配置 开发环境:jdk1.8.maven.springboot.idea 一.快速构建一个springboot项目 1.1.进入sprin ...
- 全网最详细的Linux命令系列-iptrad-ng网络流量监测命令
观察网络流量的工具:IPTRAF 想知道你的Linux系统上网络流量有多大吗?想知道是哪一块网卡承载着网络流量吗?想知道哪一个进程产生了网络流量吗?iptraf可以帮你做到.在最新的Linux rel ...
- [树形DP]战略游戏
战 略 游 戏 战略游戏 战略游戏 题目描述 Bob喜欢玩电脑游戏,特别是战略游戏.但是他经常无法找到快速玩过游戏的办法.现在他有个问题.他要建立一个古城堡,城堡中的路形成一棵树.他要在这棵树的结点上 ...
- 发送请求时携带了参数,但是浏览器network没有显示的排错思路
发送请求时携带了参数,但是浏览器network没有显示的排错思路 不知道大家有没有遇到这样子的情况就是发送请求的时候明明携带了参数,但是浏览器的network中就是没有!请看下图和代码! 我发送请求用 ...
- Python的flask接收前台的ajax的post数据和get数据
ajax向后台发送数据: ①post方式 ajax: @app.route("/find_worldByName",methods=['POST']) type:'post', d ...
- 关于MySQL日志,我与阿里P9都聊了些啥?
写在前面 周末,我与阿里P9资深技术专家(这里就不说名字了),聊起了MySQL这个话题,为啥会聊这个呢?因为他看到我出版了一部<MySQL技术大全:开发.优化与运维实战>,对书籍的评价也是 ...
- 结对作业-stage_1
教学班 罗杰.任建班周五3.4节 gitlab项目地址 Here it is. 成员 周远航(3004) 李辰洋(3477) 结对编程体验 感受 在前期设计时,两人合作可以收集更多资料,提供更多想法, ...
- 北航OO第一单元作业总结(Retake)
前言:当我写这篇博客的时候,我的心情是复杂的,因为这实际上是我第二次写这篇博客--我今年重修的这门课.我对去年的成绩心有不甘--在激烈的竞争下,我虽然尽可能完成了所有作业(仅一次作业未通过弱测),但爆 ...