Educational Codeforces Round 105 (Rated for Div. 2) 题解
Educational Codeforces Round 105 (Rated for Div. 2)
A. ABC String
枚举ABC分别为“( ”和 “ )”的情况,然后判断是否为合法字符串。
map<char,int> book;
string tt="()";
string s;bool judge(string ss)
{int num=0;for(int i=0;i<ss.length();i++){if(ss[i]=='(') num++;else num--;if(num<0) return false;}if(num==0) return true;return false;
}
bool solve()
{for(int i=0;i<2;i++)for(int j=0;j<2;j++)for(int k=0;k<2;k++){string tmp="";for(int l=0;l<s.length();l++){if(s[l]=='A') tmp+=tt[i];else if(s[l]=='B') tmp+=tt[j];else tmp+=tt[k];}if(judge(tmp)) return true;}return false;
}
int main()
{ios;int t;cin >> t;while (t--) {book.clear();cin >> s;if(solve()) cout << "YES" << endl;else cout << "NO" << endl;}
}
B. Berland Crossword
暴力枚举四个角是否为黑色,共16种情况,找到符合条件的退出。
bool s1=false,s2=false,s3=false,s4=false;
void f(int p)
{int num=p;string s="";while (num) {if(num%2) s+='1';else s+='0';num/=2;}int n=s.length();for(int i=0;i<4-n;i++) s=s+='0';for(int i=0;i<4;i++){if(s[0]=='1') s1=true;if(s[1]=='1') s2=true;if(s[2]=='1') s3=true;if(s[3]=='1') s4=true;}
}
int main()
{ios;int t;cin >> t;while (t--) {int n,u,r,d,l;cin >> n >> u >> r >> d >> l;int u1=0,r1=0,d1=0,l1=0;bool flag=false;for(int i=0;i<16;i++){u1=0,r1=0,d1=0,l1=0;s1=false,s2=false,s3=false,s4=false;f(i);if(s1) { u1++,l1++; }if(s2) { u1++,r1++; }if(s3) { r1++,d1++; }if(s4) { d1++,l1++; }if((u-u1)<n-1 && (l-l1)<n-1 && (d-d1)<n-1 && (r-r1<n-1) && u1<=u && l1<=l && d1<=d && r1<=r){ cout << "YES" << endl; flag=true;break;}}if(!flag) cout << "NO" << endl;}
}
C. 1D Sokoban
坐标正数和负数推箱子的情况是一样的,只需考虑一边即可。本题就是模拟将箱子朝一边推,箱子第一次到达每个目标点时,计算箱子覆盖目标点的个数,取最大值即可。
int a[maxn],b[maxn];
map<int,int> book;
int n,m;
vector<int> as,bs;
int f()
{book.clear();for(int i=0;i<as.size();i++) book[as[i]]=1;int sum=0;for(int i=0;i<bs.size();i++){if(book[bs[i]]==1) sum++;}int ans=sum;for(int i=0;i<bs.size();i++){if(book[bs[i]]){sum--;continue;}int num=upper_bound(as.begin(), as.end(), bs[i])-as.begin(); //bs[i]之前有多少个箱子int pos=lower_bound(bs.begin(), bs.end(),bs[i]-num+1)-bs.begin();//推的箱子刚好接触bs[i]时,之前的箱子有多少个在规定坐标上ans=max(ans,sum+i-pos+1);}return ans;
}int main()
{ios;int t;cin >> t;while (t--) {cin >> n >> m;int ans=0;for(int i=1;i<=n;i++) cin >> a[i];for(int i=1;i<=m;i++) cin >> b[i];as.clear(),bs.clear();for(int i=1;i<=n;i++){if(a[i]>0) as.pb(a[i]);}for(int i=1;i<=m;i++){if(b[i]>0) bs.push_back(b[i]);}ans+=f();as.clear(),bs.clear();for(int i=n;i>=1;i--){if(a[i]<0) as.push_back(-a[i]);}for(int i=m;i>=1;i--){if(b[i]<0) bs.push_back(-b[i]);}ans+=f();cout << ans << endl;}
}
Educational Codeforces Round 105 (Rated for Div. 2) 题解相关推荐
- Educational Codeforces Round 117 (Rated for Div. 2)题解(A~D)
Educational Codeforces Round 117 (Rated for Div. 2) 今天这场没打,赛后从九点半到十一点把前面四个题目给补了一下,E题明天有时间看看能不能弄出来. A ...
- Educational Codeforces Round 140 (Rated for Div. 2)题解
看看时间还有十几分钟,开不出来题了,写个题解 A. Cut the Triangle 检查是不是直角边平行于坐标轴的直角三角形即可 这里可以用异或来写,代码较为简洁,我就不改了,直接贴上我的丑代码 c ...
- Educational Codeforces Round 133 (Rated for Div. 2) 题解 CD
D: 这是一道好dp(对我来说) 我做的时候有想过正解那个方式当考虑到可能有重复就没有深入思考了 假设dp[i][j]代表第i次j的方案数 此时我们可以发现dp[i][j]=sum(dp[i-1][j ...
- Educational Codeforces Round 36 (Rated for Div. 2) 题解
Educational Codeforces Round 36 (Rated for Div. 2) 题目的质量很不错(不看题解做不出来,笑 Codeforces 920C 题意 给定一个\(1\)到 ...
- Educational Codeforces Round 76 (Rated for Div. 2) 题解
Educational Codeforces Round 76 题解 比赛链接 A. Two Rival Students #include<bits/stdc++.h> using na ...
- Educational Codeforces Round 105 (Rated for Div. 2) C. 1D Sokoban
题解: 我们可以得知,人可以往左边推箱子或者往右边推. 所以我们可以把所有负数放在一起,所有正数放在一起,也就是左边一堆,右边一堆. 然后开始枚举每一个special positions,假设这个点之 ...
- Educational Codeforces Round 105 (Rated for Div. 2) A-D题解
A. ABC String 题意 给你一个只包含 A.B.C的字符串,每类字符都有可能代表左右括号中的一种,问你是否能找到一个方式使得括号匹配合法 三个字符,每个字符有两种情况 总计 2^3 = 8次 ...
- Codefoece Educational Codeforces Round 83 (Rated for Div. 2)题解,(ABCDE)
比赛链接 A题: 思路:签到题. 代码: #include<bits/stdc++.h> using namespace std; typedef long long ll; const ...
- Educational Codeforces Round 93 (Rated for Div. 2) 题解
目录 A.CF1398A Bad Triangle(模拟) B.CF1398B Substring Removal Game(贪心) C.CF1398C Good Subarrays(映射) D.CF ...
最新文章
- 【廖雪峰python入门笔记】list_替换元素
- GO语言教程4:defer(延迟语句)详解
- 脱机多维数据集CUB文件的生成
- Selenium+Java+TestNG环境配置
- 怎么在CSDN中写微信公众号推文?
- C#实现监听网易邮箱
- Android 访问本地 HTML
- 编写高质量代码-OC 第7章 设计模式与Cocoa编程
- 计算机版初中语文课文原文,《背影》课文原文
- 合格的前端不少,优秀的不多
- 制作Camtasia 2020击键标记动画
- MacBook Pro 下安装 MySQL 5
- “内存型”网游外挂的刑事责任辨析
- luogu1600天天爱跑步
- 三种碎片化方法:RECAP, BRICS与eMolFrag
- 2017年是晚立秋,“秋老虎”来袭!
- 人工智能与复杂网络_为什么我与智能手机的关系变得复杂
- 任正非告别荣耀讲话—-陌生的感动
- python把文本转换为html_Python基础教程——把文本转为HTML格式
- WEPWPA Cracking on BT5/MAC
热门文章
- 机器学习路程——k近邻(KNN)算法(python实现)
- swing jtable显示html,Java Swing:基于鼠标指针下的文本显示JTable中的工具提示
- AVOSCloud(AVOSCloud.o)' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode se
- MapStructs
- 基础架构实验室-正式开源物联网平台
- mysql 基础命令进阶
- ZBar源码分析(三)
- macOS上HomeBrew安装软件慢的解决方法
- 国耀明医互联网医院:生活的烦恼谁来倾听!
- 使用echarts实现地图展示