abc088 <bfs 最短路>
1.abc306e <mutiset的使用>2.abc053d <简单贪心>3.abc042d <组合数>4.abc043d5.abc045d6.abc044d <根号分治>7.abc046d8.abc047d9.abc048d <博弈>10.abc049d <并查集>11.abc050d <???>12.abc051 <多源最短路>13.abc052d14.abc054d <dp, 背包>15.abc055d <枚举>16.abc056d <贪心 / 二分+DP+bitset>17.abc057d <贪心+组合计数>18.abc058d <公式化简>19.abc059d <博弈, 打表找规律>20.abc060d <dp, 背包>21.abc061d <单源最短路, spfa, 判断负环>22.abc062d <优先队列>23.abc063d <二分答案>24.abc064d <贪心/前缀和>25.abc309f <线段树 + 离散化 + 双指针>26.abc309e <dfs>27.abc065d <贪心+最小生成树> [lambda表达式]28.abc066d <组合>29.abc067d <博弈 + dfs>30.abc068d <思维 + 构造>31.abc069d <构造>32.abc070d <简单树上dfs>33.abc071d <递推>34.abc072d <贪心>35.abc073d <Floyed + 枚举排列>36.abc074d <Floyed 消除传递边>37.abc075d <暴力枚举 / 枚举+离散化+二维前缀和>38.abc076d <dp / 贪心>39.abc077d <思维 + 最短路 (将构造数字过程视为最短路)>40.abc078d <博弈>41.abc079d <Floyed>42.abc080d <区间重叠>43.abc081d <思维 构造>44.abc082d <bitset 状压dp>45.abc083d <思维 贪心>46.abc084d <素数筛 前缀和>47.abc085d <贪心>48.abc086d <二维前缀和 同余>49.abc087d <并查集 维护距离信息>
50.abc088 <bfs 最短路>
51.abc089 <前缀和>52.abc310d <dfs暴搜-分组方案数 / bitmask表示集合+dp>53.abc310e <公式递推(dp?)>54.abc310f <dp + bitmask>55.abc090d <枚举计数>56.abc312c <二分答案>57.abc312d <dp, 括号匹配方案数>58.abc312e <暴力>59.abc320f <dp >60.abc092d<构造,思维>61.abc094d<组合数>62.abc095d<思维>63.abc096d<素数筛,整除>64.abc097d<并查集,排列>65.abc098d<双指针,异或>66.abc099d<dfs,枚举排列方案>67.abc100d<枚举>68.abc101d<打表,数学>题目
思路
- bfs找到从起点到终点的最短路, +1(起点), 即为至少留下的白色块的个数
- 则答案 = 总白色块数 - (最短路+1)
代码
Code
// https://atcoder.jp/contests/abc088/tasks/abc088_d
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
const int N = 55;
int dis[N][N];
char g[N][N];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, 1, -1};
void solv()
{
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i ++) cin >> (g[i] + 1);
int cntw = 0;
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= m; j ++)
if (g[i][j] == '.') cntw ++;
if (g[1][1] == '#') {cout << -1; return; };
queue<PII> q;
q.push({1, 1}); dis[1][1] = 1;
while (q.size())
{
auto [x, y] = q.front(); q.pop();
for (int i = 0; i < 4; i ++)
{
int xx = x + dx[i], yy = y + dy[i];
if (xx < 1 || xx > n || yy < 1 || yy > m || dis[xx][yy] || g[xx][yy] == '#') continue;
dis[xx][yy] = dis[x][y] + 1;
q.push({xx, yy});
}
}
if (dis[n][m]) cout << cntw - dis[n][m] << endl;
else cout << -1 << endl;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int T = 1;
// cin >> T;
while (T --)
{
solv();
}
return 0;
}
本文来自博客园,作者:O2iginal,转载请注明原文链接:https://www.cnblogs.com/o2iginal/p/17556241.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律