Educational Codeforces Round 132 (Rated for Div. 2)
Educational Codeforces Round 132 (Rated for Div. 2)
A. Three Doors
简述
题意: 有三扇门(1~3), 其中两扇门后面有对应标号门的钥匙,现在手上有一把标号为n的钥匙,是否能打开所有的门?
判断现在有的钥匙 对应的门后 是否有钥匙即可,就是套娃 不是
Code
#define OK cout << (ok ? "YES" : "NO") << endl
void testcase() {
int n, ok = 0;
cin >> n;
vector<int> a(4);
for (int i = 1; i <= 3; ++i) cin >> a[i];
if (a[n] and a[a[n]]) ok = 1;
cout << (ok ? "YES" : "NO") << endl;
}
B. Also Try Minecraft
简述
题意: n个有高度的塔 ,向上飞不扣血,向下飞会扣血,每次询问判断从一个塔到另一个塔所扣的最少血
直接走过去肯定比来回走扣的血少,所以直接统计在询问的区间内会扣得血就行,前缀和预处理一下,由于可能从右向左走,要从前和从后做两遍前缀和
Code
int n, m;
cin >> n >> m;
vector<ll> a(n + 1), b(n + 1), c(n + 1);
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 2; i <= n; ++i) b[i] = b[i - 1] + max(0ll, a[i - 1] - a[i]);
for (int i = n - 1; i >= 1; --i) c[i] = c[i + 1] + max(0ll, a[i + 1] - a[i]);
while (m--) {
int x, y;
cin >> x >> y;
if (x < y) cout << b[y] - b[x] << endl;
else cout << c[y] - c[x] << endl;
}
C. Recover an RBS
简述
题意: 一个括号序列,只含' ( ' , ' ) ' , ' ? ' 三种字符,可以将?替换为括号,是否只有唯一一种方案使得这个字符串的每个括号能匹配 也就是使它变为( ( ) ) , ( ) 这种样子 题目保证最少有一种方案是它成为括号序列
要点1 : 题目保证的最少有一种方案 这意味着最后左括号和右括号都等于字符串长度的一半
要点2 : 括号序列 意味着 对于字符串的每个位置之前的右括号个数一定小于等于左括号个数
先将 '?' 替换得到一组最简单的括号序列 尝试交换所能替换的最后一个 左括号 和其之后的右括号
看替换后的序列是否为括号序列,如果是括号序列说明方案数不唯一,输出NO
Code
void testcase() {
string s; cin>>s;
int cntl=0,cntr=0;
vector<int>a;
for(int i=0;i<s.length();++i){
if( s[i] == '(' ) ++cntl;
else if(s[i]==')') ++cntr;
else a.emplace_back(i);
}
int mid=s.length()>>1;
for(int i=0,en=(int)a.size();i<en;++i){
if( i < mid-cntl ) s[a[i]] = '(';
else s[a[i]] = ')' ;
}
bool ok=true;
if(cntl<mid and cntr<mid){
swap(s[a[mid-cntl-1]],s[a[mid-cntl]]);
int cnt=0;
for(int i=0;i<s.length();++i){
if(s[i]=='(')++cnt;
else --cnt;
if(cnt<0) break;
}
if(cnt==0)ok=false;
}
cout << (ok ? "YES" : "NO") << endl;
}
D. Rorororobot
简述
机器人只能上下左右走固定的k步 每一列有从下往上的一定长度的障碍 不能走出界,是否可以从一个点到另一个点
先不看障碍判断是否可达 : 用%来判断 再看能不能找到一条路径走过去
判断是否能走过障碍:假如两个点之间有一堵高墙,每次只能跨k的距离 能不能走到最高的这堵墙与边界之间,如果可以走到就可达
Code
#define OK cout << (ok ? "YES" : "NO") << endl
template <typename T, class F = function<T(const T&, const T&)>>
class SparseTable {
public:
int n;
vector<vector<T>> mat;
F func;
SparseTable(const vector<T>& a, const F& f) : func(f) {
n = static_cast<int>(a.size());
debug(n);
int max_log = 32 - __builtin_clz(n);
mat.resize(max_log);
mat[0] = a;
for (int j = 1; j < max_log; j++) {
mat[j].resize(n - (1 << j) + 1);
for (int i = 0; i <= n - (1 << j); i++) {
mat[j][i] = func(mat[j - 1][i], mat[j - 1][i + (1 << (j - 1))]);
}
}
}
T get(int from, int to) const {
assert(0 <= from && from <= to && to <= n - 1);
int lg = 32 - __builtin_clz(to - from + 1) - 1;
return func(mat[lg][from], mat[lg][to - (1 << lg) + 1]);
}
};
void testcase() {
int n, m;
cin >> n >> m;
vector<int> a(m);
for (int& i : a) cin >> i;
SparseTable<int> st(a, [&](int i, int j) { return max(i, j); });
int q;
cin >> q;
while (q--) {
int sx, sy, tx, ty, k;
cin >> sx >> sy >> tx >> ty >> k;
int x = abs(sx - tx), y = abs(sy - ty);
bool ok = false;
if (x % k and y % k) {
OK;
continue;
}
int now = tx + (n - tx - (n - tx) % k);
if (sy > ty) swap(sy, ty);
int mx = st.get(sy - 1, ty - 1);
if (now > mx) ok = true;
OK;
}
}
EF 待补
Educational Codeforces Round 132 (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 ...
随机推荐
- Spring Boot下Spring Batch入门实例
一.About Spring Batch是什么能干什么,网上一搜就有,但是就是没有入门实例,能找到的例子也都是2.0的,看文档都是英文无从下手~~~,使用当前最新的版本整合网络上找到的例子. 关于基础 ...
- 安装Zookeeper到Linux
系统版本:Ubuntu 16.04.5 LTS 软件版本:apache-zookeeper-3.5.8 硬件要求:无 1.安装依赖 Zookeeper需要JDK的支持. 注:需要先去JDK官网下载安装 ...
- python目录索引
python目录索引 python基础数据类型1 目录 part1 part2 运算符 格式化 part3 字符串 字符串常用操作方法 part4 列表 列表的创建: 列表的索引,切片 列表的增删改查 ...
- 服务器安装mysql遇到的坑
服务器安装mysql遇到的坑 一.CentOS7安装MySQL 1.下载:MySQL官方的 Yum Repository wget -i -c http://dev.mysql.com/get/mys ...
- Amazon 消息订阅对接
亚马逊的api 谁用谁知道...... 除了坑还是坑 头疼一周整出来,分享给铁汁们 amazon 的订阅思维,我只能说外国人脑回路有点长 下面就讲讲具体流程步骤: 第一步: 参照官方教程:设置通知(A ...
- 开发工具-Redis Desktop Manager下载地址
更新记录 2022年6月10日 完善标题. 官方: https://github.com/uglide/RedisDesktopManager 免费打包版: https://github.com/le ...
- 基于Kubernetes v1.24.0的集群搭建(二)
上一篇文章主要是介绍了,每台虚拟机的环境配置.接下来我们开始有关K8S的相关部署. 另外补充一下上一篇文章中的K8S的changelog链接: https://github.com/kubernet ...
- 关键字——this,super,static,final
this 理解为当前对象. //测试 public static void main(String[] args){ Person person = new Person(3, "xiaoM ...
- 分布式机器学习:同步并行SGD算法的实现与复杂度分析(PySpark)
1 分布式机器学习概述 大规模机器学习训练常面临计算量大.训练数据大(单机存不下).模型规模大的问题,对此分布式机器学习是一个很好的解决方案. 1)对于计算量大的问题,分布式多机并行运算可以基本解决. ...
- Pyinstaller打包pikepdf失败的问题排查
问题 最近在项目里用到了pikepdf这个库,用于实现pdf水印插入的一个小功能,源码调试阶段运行一切OK但是在出包时报了如下异常. Traceback (most recent call last) ...