A. Potions
int solve() {
int n, h, x; cin >> n >> h >> x;
int y = x - h, res = 0, minn = 1e3;
for (int i = 1; i <= n; i ++) {
int x; cin >> x;
if (x >= y && x < minn) {
res = i;
minn = y - x;
}
}
return res;
}
B. MissingNo.
int solve() {
int n; cin >> n;
set<int> s;
int l = 1e3, r = 1;
while (n --) {
int x; cin >> x;
l = min(l, x);
r = max(r, x);
s.insert(x);
}
for (int i = l + 1; i < r; i ++) if (!s.count(i)) return i;
}
C. Remembering the Days
题意 求权值和最大的一条路径
Tag dfs
int n, m, res;
vector<vector<int>> v(N);
vector<vector<int>> d(N, vector<int>(N));
vector<bool> vis(N);
void dfs(int x, int dis) {
vis[x] = true;
bool flag = true;
for (auto i : v[x]) {
if (vis[i]) continue;
flag = false;
dfs(i, dis + d[x][i]);
}
if (flag) res = max(res, dis);
vis[x] = false;
}
int solve() {
cin >> n >> m;
while (m --) {
int a, b, c; cin >> a >> b >> c;
v[a].push_back(b);
v[b].push_back(a);
d[a][b] = d[b][a] = c;
}
for (int i = 1; i <= n; i ++) {
vis.assign(vis.size(), false);
dfs(i, 0);
}
return res;
}
D. President
ll solve() {
int n; cin >> n;
vector<ll> f{0};
ll sum = 0;
for (int i = 0; i < n; i ++) {
int x, y, z; cin >> x >> y >> z;
sum += z;
int cost = max(0, (x + y + 1) / 2 - x);
f.resize(sum + 1, inf);
for (int i = sum; i >= z; i --)
f[i] = min(f[i], f[i - z] + cost);
}
return *min_element(f.begin() + (sum + 1) / 2, f.end());
}
E. Avoid Eye Contact
题意
n
×
m
n×m
n×m 的迷宫,.
代表可以走,#
代表障碍物,<>^v
代表射线,射线方向不能走,知道射线遇到非 .
的格子,求最短路文章来源:https://www.toymoban.com/news/detail-686129.html
Tag bfs
文章来源地址https://www.toymoban.com/news/detail-686129.html
int solve() {
cin >> n >> m;
for (int i = 0; i < n; i ++) cin >> s[i];
for (int i = 0; i < n; i ++)
for (int j = 0; j < m; j ++)
d[i][j] = -1, vis[i][j] = false;
for (int i = 0; i < n; i ++) {
for (int j = 0; j < m; j ++) {
char c = s[i][j];
int op = 0;
if (c == '#') vis[i][j] = true;
else if (c == 'S') sx = i, sy = j;
else if (c == 'G') gx = i, gy = j;
else if (c == '>') op = 1;
else if (c == '<') op = 2;
else if (c == 'v') op = 3;
else if (c == '^') op = 4;
if (!op) continue;
int px = i, py = j;
while (check(px, py) && (s[px][py] == '.' || i == px && j == py)) {
vis[px][py] = true;
px += dx[op], py += dy[op];
}
}
}
d[sx][sy] = 0;
queue<Node> q;
q.push({sx, sy});
while (!q.empty()) {
Node t = q.front();
q.pop();
for (int i = 1; i < 5; i ++) {
int px = t.x + dx[i], py = t.y + dy[i];
if (!check(px, py) || vis[px][py] || d[px][py] != -1) continue;
d[px][py] = d[t.x][t.y] + 1;
q.push({px, py});
}
}
return d[gx][gy];
}
到了这里,关于AtCoder Beginner Contest 317 题解 ABCDE | JorbanS的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!