3.9w+
社区成员
第 1 题:0的个数
第 2 题:超级质数
第 3 题:卡牌
第 4 题:染色时间
必看:我发现很多同学每次都只写填空题,编程题全空着,但是填空题只有10分,总分150分。这样你即使坚持了30天,又有什么作用呢?即使3,4题你做不出,也尝试去写暴力程序,看可以拿下多少分,基本上任何编程题都是可以写暴力程序得分的,你现在遇见一个不会的就空着,你比赛的时候想写暴力也只能干瞪眼。所以大家即使后面两题怎么也学不会,也请努力去得分,可以贴上暴力程序的代码和你过了多少个样例的截图
只要写了一题,就可以打卡,有什么不懂的可以群内讨论
打卡的截止时间暂定于晚上11:50点
打卡方式:1
去年泡泡的打卡专栏,适合对自己要求较高和有空的同学可以写博客,大家可以学习:https://blog.csdn.net/qq_45400861/category_11673506.html?spm=1001.2014.3001.5482
发博客方式:
打卡方式:2
也可以直接社区发帖粘贴上自己打卡题的代码和AC截图
发帖模板比如:https://bbs.csdn.net/topics/613476519
发帖方式选择发帖:
选择正确频道
将你发的文章或者帖子的链接复制,点击下面的提交按钮即可:
心情很好,那就来杯奶茶叭
心情不好,那就来一碗螺蛳粉吧!
思路:假设 x 和 y是相邻的两点,t[i]代表点i的染色时间。如果我们从 x 走到 y,因为我们到达x的时候 y 会开始染色,经过 t[y] 秒后染色完毕,那么显然是一条单向边从 x 到 y 且权值为 t[y]。相反从 y 到 x会有一条到达权值为 t[x]的单向边。对任意相邻两个点进行建边,注意dist[0]等于t[0]而不是0,点数2e5,跑一遍优化版dijkstra即可。
染色时间参考代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int, int> PII;
#define pb(s) push_back(s);
#define SZ(s) ((int)s.size());
#define ms(s,x) memset(s, x, sizeof(s))
#define all(s) s.begin(),s.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const int N = 300010;
int n, m;
std::vector<PII> e[N];
LL dist[N];
bool st[N];
void dijkstra(int start, int v)
{
memset(dist, 0x3f, sizeof(dist));
dist[start] = v;
priority_queue<PII, vector<PII>, greater<PII>> heap;
heap.push({v, start});
while (heap.size())
{
auto t = heap.top();
heap.pop();
int ver = t.second, distance = t.first;
if (st[ver]) continue;
st[ver] = true;
for (auto [j, x] : e[ver])
{
if (dist[j] > dist[ver] + x) {
dist[j] = dist[ver] + x;
heap.push({dist[j], j});
}
}
}
}
void solve()
{
cin >> n >> m;
std::vector<std::vector<int>> a(n, std::vector<int>(m));
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j)
cin >> a[i][j];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (i != n - 1) {
int u = i * m + j, v = (i + 1) * m + j;
e[u].push_back({v, a[i + 1][j]});
e[v].push_back({u, a[i][j]});
}
if (j != m - 1) {
int u = i * m + j, v = i * m + j + 1;
e[u].push_back({v, a[i][j + 1]});
e[v].push_back({u, a[i][j]});
}
}
}
dijkstra(0, a[0][0]);
LL ans = 0;
for (int i = 0; i < n * m; ++i) ans = max(ans, dist[i]);
cout << ans << '\n';
}
int main()
{
ios_base :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t = 1;
while (t--)
{
solve();
}
return 0;
}
```c++
```