A - Journey Planning

题意: 有一列共 n 个城市, 每个城市有美丽值 b[i], 要访问一个子序列的城市, 这个子序列相邻项的原项数之差等于美丽值之差, 求最大的美丽值总和.

思路: 对于一个合法的子序列, b[i] - i 结果是一个定值, 统计该值取最大.

view code
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inc(i, l, r) for (int i = l; i <= r; i++) const int maxn = 1e6 + 5; int n, b[maxn]; int main() {
cin >> n;
map<int, ll> a;
inc(i, 0, n - 1) {
cin >> b[i];
a[b[i] - i] += b[i];
}
ll res = 0;
for (auto ite : a) res = max(res, ite.second);
cout << res << "\n";
}

 

B - Navigation System

题意: 给出一个有向图和一个人的行动路径, 这个人每次移动前导航仪会给出从当前点到终点的一条最短路线, 如果这个人移动的路线与之不符, 导航仪会重新生成从下一个点出发到终点的最短路线. 问导航仪生成新路线的最小和最大次数.

思路: bfs求出所有点到终点的最短距离. 如果这个人移动时距离终点不是-1, 那他这次移动一定不在最短路线上; 否则, 检查是否有其他使距离-1的路线, 如果有, 那么就知道导航仪可能会重新生成路线.

view code
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inc(i, l, r) for (int i = l; i <= r; i++) const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f; vector<int> g[maxn];
vector<int> rg[maxn];
int a[maxn], d[maxn], vis[maxn];
int n, m, u, v, k; int main() {
memset(d, 63, sizeof(d));
cin >> n >> m;
inc(i, 1, m) {
cin >> u >> v;
rg[u].push_back(v);
g[v].push_back(u);
}
cin >> k;
inc(i, 1, k) cin >> a[i];
queue<int> que;
que.push(a[k]);
d[a[k]] = 0;
vis[a[k]] = 1;
while (que.size()) {
int p = que.front();
que.pop();
inc(i, 0, (int)g[p].size() - 1) {
if (!vis[g[p][i]]) {
d[g[p][i]] = d[p] + 1;
que.push(g[p][i]);
vis[g[p][i]] = 1;
}
}
}
int res1 = 0, res2 = 0;
for (int i = 1; i < k; i++) {
int now = a[i], nxt = a[i + 1];
if (d[now] != d[nxt] + 1)
res1++, res2++;
else
inc(j, 0, (int)rg[now].size() - 1) {
if (d[rg[now][j]] + 1 == d[now] && rg[now][j] != nxt) {
res2++;
break;
}
}
}
cout << res1 << " " << res2;
}

 

C - World of Darkraft: Battle for Azathoth

题意: 给出 n 个武器, m 个防具, 分别有攻击力 ai 和防御力 bi, 购买该装备需要的金币ci, 还有 p 个怪兽, 分别具有防御力 xi, 攻击力 yi, 打败它获得的金币 ci. 现要求从中武器和防具中各选出恰好一个, 然后就可以打败所有满足 ai > xj 且 bi > yj 的怪兽并获得 cj. 求最大获利.

思路: 预处理攻击力和防御力达到 x 最少需要支付的金币数 atk[x], def[x]. 对所有怪兽排序(不妨以 xi 为第一关键字), 扫描一遍, 维护这样的线段树: 防御力为 x 时的最大获利, 每个节点初始值为 -def[x], 表示为了该防具需要支付的金币数. 每扫过一只怪兽, 防御力足以打败该怪兽的范围就增加 ci, 而武器攻击力为当前怪兽的 xi + 1, 这样可以确保前面扫描过的怪兽都满足 ai > xj.

view code
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inc(i, l, r) for (int i = l; i <= r; i++)
#define dec(i, l, r) for (int i = l; i >= r; i--)
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f; int n, m, p;
int atk[maxn], def[maxn];
struct node {
int a, b, c;
bool operator<(const node &o) const {
if (a == o.a) return b < o.b;
return a < o.a;
}
} mos[maxn];
int x, y, c, matk, mdef; ll f[4 * maxn], mv[4 * maxn]; void up(int k) { mv[k] = max(mv[k << 1], mv[k << 1 | 1]); }
void down(int k) {
f[k << 1] += f[k], f[k << 1 | 1] += f[k];
mv[k << 1] += f[k], mv[k << 1 | 1] += f[k];
f[k] = 0;
}
void build(int k, int l, int r) {
if (l == r) {
mv[k] = -def[l];
return;
}
int mid = l + r >> 1;
build(k << 1, l, mid);
build(k << 1 | 1, mid + 1, r);
up(k);
}
void add(int k, int l, int r, int val, int a, int b) {
if (a <= l && r <= b) {
mv[k] += val, f[k] += val;
return;
}
down(k);
int mid = l + r >> 1;
if (a <= mid) add(k << 1, l, mid, val, a, b);
if (b > mid) add(k << 1 | 1, mid + 1, r, val, a, b);
up(k);
} int main() {
memset(atk, 127, sizeof(atk));
memset(def, 127, sizeof(def));
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> p;
inc(i, 1, n) {
cin >> x >> c;
atk[x] = min(atk[x], c);
matk = max(x, matk);
}
dec(i, matk - 1, 1) atk[i] = min(atk[i], atk[i + 1]);
inc(i, 1, m) {
cin >> x >> c;
def[x] = min(def[x], c);
mdef = max(x, mdef);
}
dec(i, mdef - 1, 1) def[i] = min(def[i], def[i + 1]);
build(1, 1, mdef);
inc(i, 0, p - 1) {
cin >> x >> y >> c;
mos[i] = {x, y, c};
}
sort(mos, mos + p);
ll res = -atk[1] - def[1];
inc(i, 0, p - 1) {
if (mos[i].b < mdef) add(1, 1, mdef, mos[i].c, mos[i].b + 1, mdef);
if (mos[i].a < matk) res = max(res, mv[1] - atk[mos[i].a + 1]);
}
cout << res;
}

 

D - Reachable Strings

题意: 给出一个串 s, 和 q 组查询, 询问 s 的两个子串是否是 Reachable. 所谓 Reachable 是指将一个串的子串 "011" 变为 "110" 或者把 "110" 变为 "011", 可以变换多次. |s| ≤ 2e5, q ≤ 2e5.

思路: 这个变换操作的本质就是将 "0" 移动并穿过若干个 "11". 将串 s 中成对相邻的 "1" 都去掉得到串 t, 此时 Reachable 就等价于在 t 中的对应子串一样. 这个可以用 Hash 判断. 注意子串在变换到 t 时左右两边省略掉的 "1" 奇偶性也得一致.

view code
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inc(i, l, r) for (int i = l; i <= r; i++)
#define dec(i, l, r) for (int i = l; i >= r; i--) const int maxn = 2e5 + 5;
const int mod0 = 1e9 + 7;
const int mod1 = 1e9 + 9;
const int BASE = 2; int n, l1, l2, len, q;
char s[maxn]; int num[maxn];
ll hash0[maxn], hash1[maxn];
ll pow0[maxn], pow1[maxn];
int l[maxn], r[maxn], pos[maxn]; string t = "#"; int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> s + 1 >> q;
dec(i, n, 1) r[i] = s[i] == '1' ? r[i + 1] + 1 : 0;
inc(i, 1, n) l[i] = s[i] == '1' ? l[i - 1] + 1 : 0;
inc(i, 1, n) {
if (s[i] == '0') {
pos[i] = t.size();
t += '0';
} else if (t.back() == '1') {
t.pop_back();
} else {
t += '1';
}
}
int len = t.size() - 1;
pow0[0] = pow1[0] = 1;
inc(i, 1, len) {
pow0[i] = pow0[i - 1] * BASE % mod0;
pow1[i] = pow1[i - 1] * BASE % mod1;
hash0[i] = (hash0[i - 1] * BASE + t[i] - '0') % mod0;
hash1[i] = (hash1[i - 1] * BASE + t[i] - '0') % mod1;
} inc(ca, 1, q) {
cin >> l1 >> l2 >> len;
int z1 = l1 + r[l1], y1 = l1 + len - 1 - l[l1 + len - 1];
int z2 = l2 + r[l2], y2 = l2 + len - 1 - l[l2 + len - 1];
if (z1 > y1 && z2 > y2) {
cout << "Yes\n";
continue;
}
if (z1 > y1 || z2 > y2) {
cout << "No\n";
continue;
}
if (r[l1] % 2 != r[l2] % 2 ||
l[l1 + len - 1] % 2 != l[l2 + len - 1] % 2) {
cout << "No\n";
continue;
} z1 = pos[z1] - 1, y1 = pos[y1], z2 = pos[z2] - 1, y2 = pos[y2]; if (y1 - z1 == y2 - z2 &&
(hash0[y1] + (mod0 - pow0[y1 - z1]) * hash0[z1]) % mod0 ==
(hash0[y2] + (mod0 - pow0[y2 - z2]) * hash0[z2]) % mod0 &&
(hash1[y1] + (mod1 - pow1[y1 - z1]) * hash1[z1]) % mod1 ==
(hash1[y2] + (mod1 - pow1[y2 - z2]) * hash1[z2]) % mod1) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
}

 

Codeforces Round #625 (1A - 1D)的更多相关文章

  1. Codeforces Round #625 (Div. 2)

    Contest Info Practice Link Solved A B C D E F 4/6 O O Ø  Ø     O 在比赛中通过 Ø 赛后通过 ! 尝试了但是失败了 - 没有尝试 Sol ...

  2. Codeforces Round #625 Div. 2 D E

    D题:https://codeforces.com/contest/1321/problem/D 题意:题目给个有向图,然后给一段序列,我们要沿着这个序列走,问走的过程中当前点到t的最短路会重构多少次 ...

  3. Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) D. Navigation System(有向图,BFS,最短路)

    题意: n 点 m 边有向图,给出行走路径,求行走途中到路径终点最短路变化次数的最小值和最大值 . 思路 : 逆向广搜,正向模拟. #include <bits/stdc++.h> usi ...

  4. Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) C. Remove Adjacent(字符串,贪心,枚举)

    题意: 给你一个由小写字母组成的字符串,若串中两个相邻元素字典序中也相邻,移除较大字母,问最多能移除多少个字母. 思路: 从大到小依次枚举. Tips: 注意下标的处理. 以小消大: #include ...

  5. Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) B. Journey Planning(映射)

    题意: 已知 n 所城市(从 1 至 n 编号)及其美丽值,选取一条旅行路线,满足路线中两两城市美丽值之差等于编号之差,求所有旅行路线中美丽值的最大值. 思路: 美丽值与编号作差,差值为键,映射累加 ...

  6. Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) A. Contest for Robots(数学)

    题意: n 道题,2 个答题者,已知二者的做题情况,你是受贿裁判,可以给每题指定分值(≥1),求甲乙分数(甲>乙)相差最小时最大分值的最小值. 思路: 统计只有甲或乙做出的题目数. 加一取下整判 ...

  7. CF922 CodeForces Round #461(Div.2)

    CF922 CodeForces Round #461(Div.2) 这场比赛很晚呀 果断滚去睡了 现在来做一下 A CF922 A 翻译: 一开始有一个初始版本的玩具 每次有两种操作: 放一个初始版 ...

  8. [Codeforces Round #340 (Div. 2)]

    [Codeforces Round #340 (Div. 2)] vp了一场cf..(打不了深夜的场啊!!) A.Elephant 水题,直接贪心,能用5步走5步. B.Chocolate 乘法原理计 ...

  9. Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements (思维,前缀和)

    Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements time limit per test 1 se ...

随机推荐

  1. Ado.net 02

    1.连接字符串不同,连接池也不同 SqlConnection对象只能被打开一次.但是在Close()后再进行Open()操作.但是在Dispose()之后就不能再Open()了. 2.SqlDataA ...

  2. overflow-y:auto/hidden/scroll和overflow-x:visible组合渲染异常

    最近做项目想做一个这样的效果:就是我想要内部div x轴溢出div则显示y轴溢出div则出现滚动条于是用到了overflow-y 和 overflow-x 这个css属性原来以为css中直接设置就ok ...

  3. HTML与CSS 开发常用语义化命名

    一.布局❤️ header 头部/页眉:index 首页/索引:logo 标志:nav/sub_nav 导航/子导航:banner 横幅广告:main/content 主体/内容:container/ ...

  4. 解决Sprite Atlas打包Asset bundles时重复打包的问题

    0x00 前言 在Unity 2018.4.6之前的版本,有一个和SpriteAtlas打AB包有关的常见问题.即当给Sprite Atlas打AB包时,Sprite Atlas Texture可能会 ...

  5. Promise,Generator,Await/Async

    上节中忘记讲:Iterator接口和Generator函数的关系了,Symbol.iterator方法的最简单的实现就是通过Generator函数: let myIterable = { [Symbo ...

  6. Python学习字典.基础三

    元组   Python的元组与列表类似,不同之处在于元组的元素不能修改. 元组使用小括号,列表使用方括号. 元组中要定义的元组中只有一个元素需要再元素后面加逗号,用来消除数学歧义.例 t=(1,)   ...

  7. Java中的IO与NIO

    前文开了高并发学习的头,文末说了将会选择NIO.RPC相关资料做进一步学习,所以本文开始学习NIO知识. IO知识回顾 在学习NIO前,有必要先回顾一下IO的一些知识. IO中的流 Java程序通过流 ...

  8. redis实现数据库(一)

    转:https://www.cnblogs.com/beiluowuzheng/p/9738159.html 服务器中的数据库 Redis服务器将所有数据库都保存在服务器状态redis.h/redis ...

  9. ZooKeeper原理解析

    目录 ZooKeeper中的各种角色 ZooKeeper与客户端 Zookeeper节点数据操作流程 Paxos 算法概述(ZAB 协议) ZooKeeper 的选主机制 选择机制中的概念 选举消息内 ...

  10. 2019-2020-2 20174313张博《网络对抗技术》Exp2-后门原理与实践

    一.实验名称 后门原理与实践. 二.实验目的与要求 ·掌握后门的概念,知道常见的后门种类,深入理解后门的运作原理. ·掌握几种常见的后门工具,学会利用后门工具进行一些简单操作. ·增强信息安全意识,认 ...