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)的更多相关文章

  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. 每天一个 HTTP 状态码 202

    202 Accepted 202 Accepted 表示服务器已经接受了这个请求,但是还不确定这个请求是否能够成功地被处理完.该请求最终可能会或可能不会被执行,并且在处理发生时可能会被拒绝,这是不确定 ...

  2. Redis 全局通用命令整理

    转载请注明出处: 1.查看所有键 keys * 该命令会存在线程阻塞问题,keys 命令也可以通过正则匹配获取存在的缓存数据 2.查看键总数 dbsize dbsize命令会返回当前数据库中键的总数. ...

  3. 免申请直接用上 IDEA 新 UI,只需要这三步配置

    早上给大家介绍了IDEA官方宣布正在开发一套全新的UI,但目前是预览版需要申请才能体验. 随后马上就有网友分享了,不需要申请直接就能激活体验的方法. 本期视频:https://www.bilibili ...

  4. android系统中有哪些日志

    日志目录 android系统中还有很多常用的日志目录.我们可以通过adb命令把这些日志信息提取出来. data/system/dropbox data/system/usagestats data/s ...

  5. 2021.03.06【NOIP提高B组】模拟 总结

    T1 看起来十分复杂,打表后发现答案是 \(n*m\mod p\) 具体的证明... 原式的物理意义,就是从坐标原点(0,0),用每一种合法的斜率, 穿过坐标[1 ~ n , 1 ~ m]的方阵中的整 ...

  6. 17.Nginx 重写(location rewrite)

    Nginx 重写(location / rewrite) 目录 Nginx 重写(location / rewrite) 常见的nginx正则表达式 location lication的分类 loca ...

  7. 静态代理、动态代理与Mybatis的理解

    静态代理.动态代理与Mybatis的理解 这里的代理与设计模式中的代理模式密切相关,代理模式的主要作用是为其他对象提供一种控制对这个对象的访问方法,即在一个对象不适合或者不能直接引用另一个对象时,代理 ...

  8. 《ECMAScript 6 入门》【三、字符串的扩展】(持续更新中……)

    前言: 本篇介绍 ES6 对字符串的改造和增强.一.字符的 Unicode 表示法 字符的 Unicode 码点必须在\u0000~\uFFFF之间,\uxxxx形式表示一个字符,其中xxxx表示字符 ...

  9. XMAL中的x是何方神僧

    在一开始我们接触WPF时,总是被小X牵着鼻子走,还不知道它是谁,比如 <Window x:Class="Blend_WPF.WindowStyle"        xmlns ...

  10. Linux文本管理命令

    touch命令: 创建空文件:touch newfile 也可以使用重定向符(>)创建空文件: > newfile 刷新文件时间: touch 已经存在的文件 cp命令:文件的复制 选项: ...