AtCoder Beginner Contest 176 (ABC水题,D题01BFS,E数组处理)
补题链接:Here
A - Takoyaki
很容易看出 \(\frac{N + X - 1}{X} \times T\)
B - Multiple of 9
给定一个很大的整数,问其是否是 \(9\) 的倍数
累加各个位数,然后判断取余结果
C - Step
给定一个数组,每次操作可以给一个数增加 \(1\) ,问最少多少次操作可以将数组变为不下降序列?
贪心地将当前数字加大到左边的最大值即可,如果当前数字大于最大值,则更新最大值。
D - Wizard in Maze
题意:有一个巫师在迷宫中,要从起点到终点。有两种走法:一是直接沿着路走,二是使用魔法,跳到以当前格子为中心的 \(5\times5\) 方阵中任意一个没有障碍的格子上。问最少用几次魔法,可以到终点?如果无解,输出 \(−1\)。
思路:经典 01 BFS,沿着路走的代价为 \(0\),而使用魔法的代价为 \(1\)。使用标准的 0-1BFS,也即双端队列来处理即可。
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int inf = 0x3f3f3f3f;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int h, w, sx, sy, ex, ey;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
cin >> h >> w >> sx >> sy >> ex >> ey;
sx--, sy--, ex--, ey--;
vector<string> a(h);
for (int i = 0; i < h; ++i) cin >> a[i];
vector<vector<int>> dist(h, vector<int>(w, inf));
vector<vector<bool>> vis(h, vector<bool>(w, false));
deque<pair<int, int>> q;
q.push_back({sx, sy});
dist[sx][sy] = 0;
while (q.size()) {
auto f = q.front();
q.pop_front();
int ci = f.first, cj = f.second;
if (ci == ex && cj == ey) {
cout << dist[ci][cj] << "\n";
return 0;
}
if (vis[ci][cj]) continue;
vis[ci][cj] = true;
for (int k = 0; k < 4; ++k) {
int ni = ci + dy[k], nj = cj + dx[k];
if (ni < 0 || ni >= h || nj < 0 || nj >= w ||
dist[ni][nj] <= dist[ci][cj] || a[ni][nj] == '#')
continue;
dist[ni][nj] = dist[ci][cj];
q.push_front({ni, nj});
}
for (int ni = ci - 2; ni <= ci + 2; ++ni)
for (int nj = cj - 2; nj <= cj + 2; ++nj) {
if (ni < 0 || ni >= h || nj < 0 || nj >= w || a[ni][nj] == '#' ||
dist[ni][nj] <= dist[ci][cj] + 1)
continue;
dist[ni][nj] = dist[ci][cj] + 1;
q.push_back({ni, nj});
}
}
cout << -1 << "\n";
return 0;
}
E - Bomber
有一个 \(H\times W\) 的大方阵,其中若干位置有目标物。可以设置一个炮台,炮台可以攻击同一行和同一列的所有目标。问炮台最多能攻击多少个目标?
思路:\(1 \le H,W\le 3e5\) 可想而知暴力会 TLE,
我们可以在读入的时候就维护好每行每列的目标个数,然后找到最大值的行列(可能有多个)
然后一次遍历这些点。
注意可能刚好炮塔落点的位置上有目标,然后就会重复计算一次
// Murabito-B 21/04/07
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int h, w, m;
cin >> h >> w >> m;
vector<int> hc(h + 1), wc(w + 1);
vector<pair<int, int>> p(m);
for (int i = 0; i < m; ++i) {
cin >> p[i].first >> p[i].second;
hc[p[i].first]++, wc[p[i].second]++;
}
int hm = *max_element(hc.begin(), hc.end());
int wm = *max_element(wc.begin(), wc.end());
vector<int> vh, vw;
for (int i = 1; i <= h; ++i)
if (hc[i] == hm) vh.emplace_back(i);
for (int i = 1; i <= w; ++i)
if (wc[i] == wm) vw.emplace_back(i);
int sh = vh.size(), sw = vw.size();
if (sh * sw > m) {
cout << hm + wm;
return 0;
}
set<pair<int, int>> s(p.begin(), p.end());
for (int i : vh)
for (int j : vw)
if (!s.count({i, j})) {
cout << hm + wm;
return 0;
}
cout << hm + wm - 1;
return 0;
}
F - Brave CHAIN
待补。。。
AtCoder Beginner Contest 176 (ABC水题,D题01BFS,E数组处理)的更多相关文章
- AtCoder Beginner Contest 050 ABC题
A - Addition and Subtraction Easy Time limit : 2sec / Memory limit : 256MB Score : 100 points Proble ...
- AtCoder Beginner Contest 088 (ABC)
A - Infinite Coins 题目链接:https://abc088.contest.atcoder.jp/tasks/abc088_a Time limit : 2sec / Memory ...
- AtCoder Beginner Contest 087 (ABC)
A - Buying Sweets 题目链接:https://abc087.contest.atcoder.jp/tasks/abc087_a Time limit : 2sec / Memory l ...
- AtCoder Beginner Contest 176
比赛链接:https://atcoder.jp/contests/abc176 A - Takoyaki #include <bits/stdc++.h> using namespace ...
- AtCoder Beginner Contest 176 D - Wizard in Maze (BFS,双端队列)
题意:给你一张图,"."表示能走,"#表示不能走,步行可以向四周四个方向移动一个单位,使用魔法可以移动到周围\(5\)X\(5\)的空地,问能否从起点都早终点,并求最少使 ...
- AtCoder Beginner Contest 176 E - Bomber (思维)
题意:有一张\(H\)x\(W\)的图,给你\(M\)个目标的位置,你可以在图中放置一枚炸弹,炸弹可以摧毁所在的那一行和一列,问最多可以摧毁多少目标. 题解:首先我们记录某一行和某一列目标最多的数目, ...
- AtCoder Beginner Contest 253 F - Operations on a Matrix // 树状数组
题目传送门:F - Operations on a Matrix (atcoder.jp) 题意: 给一个N*M大小的零矩阵,以及Q次操作.操作1(l,r,x):对于 [l,r] 区间内的每列都加上x ...
- AtCoder Beginner Contest 068 ABCD题
A - ABCxxx Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement This contes ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 223
AtCoder Beginner Contest 223 A是纯纯的水题,就不说了 B - String Shifting 思路分析 我真的sb,一开始想了好久是不是和全排列有关,然后读了好几遍题目也 ...
随机推荐
- Walrus 0.4发布:单一配置、多态运行,体验下一代应用交付模型
今天,我们高兴地宣布云原生统一应用平台 Walrus 0.4 正式发布,这是一个里程碑式的版本更新.新版本采用了全新的应用模型--仅需进行单一配置,即可在多种模态的基础设施及环境中运行包括应用服务及周 ...
- 【源码系列#02】Vue3响应式原理(Effect)
专栏分享:vue2源码专栏,vue3源码专栏,vue router源码专栏,玩具项目专栏,硬核推荐 欢迎各位ITer关注点赞收藏 Vue3中响应数据核心是 reactive , reactive 的实 ...
- Grid 拖拽布局实现
最近有个需求需要实现自定义首页布局,需要将屏幕按照 6 列 4 行进行等分成多个格子,然后将组件可拖拽对应格子进行渲染展示. 示例 对比一些已有的插件,发现想要实现产品的交互效果,没有现成可用的.本身 ...
- 手撸一个SpringBoot配置中心实现配置动态刷新
业务需求 SpringBoot项目配置信息大多使用@Value注解或者@ConfigurationProperties注解读取配置信息,线上项目经常需要对某些配置进行调整,如果每次都需要修改配置文件再 ...
- [ABC299F] Square Subsequence
Problem Statement You are given a string $S$ consisting of lowercase English letters. Print the numb ...
- 【教程】浅谈ios混淆和加固加密
混淆: 针对项目代码,代码混淆通常将代码中的各种元素(变量.函数.类名等)改为无意义的名字,使得阅读的人无法通过名称猜测其用途,增大反编译者的理解难度. 虽然代码混淆可以提高反编译的门槛,但是对开 ...
- C++ Qt开发:TabWidget实现多窗体功能
Qt 是一个跨平台C++图形界面开发库,利用Qt可以快速开发跨平台窗体应用程序,在Qt中我们可以通过拖拽的方式将不同组件放到指定的位置,实现图形化开发极大的方便了开发效率,本章将重点介绍TabWidg ...
- 小傅哥自研插件,为开发提效80%,已经有8.1k安装量!
作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 哈喽,大家好我是技术UP主小傅哥. 如果你担心维护成本和性能考量,不想使用 BeanUtils ...
- Windows 设置 VMware workstation 虚拟机开机启动
参考 https://www.cnblogs.com/qmfsun/p/6284236.html http://www.cnblogs.com/eliteboy/p/7838091.html 司徒晓宇 ...
- 文心一言 VS 讯飞星火 VS chatgpt (144)-- 算法导论12.1 4题
四.用go语言,对于一棵有 n 个结点的树,请设计在 O(n)时间内完成的先序遍历算法和后序遍历算法. 我个人喜欢 灵小智 . 文心一言: 在 Go 语言中,我们可以使用递归来实现树的前序遍历和后序遍 ...