Skip to content

Commit 78dc083

Browse files
committed
HDOJ: 2024“钉耙编程”中国大学生算法设计超级联赛(2)
1 parent 3fa7c5e commit 78dc083

File tree

7 files changed

+470
-0
lines changed

7 files changed

+470
-0
lines changed

HDOJ/7445.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @file 7445.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2024-07-22
5+
*
6+
* @copyright Copyright (c) 2024
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#define endl '\n'
14+
15+
typedef pair<int, int> pii;
16+
17+
void solve(void) {
18+
vector<pii> ans;
19+
20+
int n, n1 = 1;
21+
cin >> n;
22+
for (int i = 1; i * 3 <= n; i++) {
23+
ans.emplace_back(min(i, 3), i + 1);
24+
ans.emplace_back(min(i, 2), i + 2);
25+
ans.emplace_back(min(i, 1), i + 3);
26+
n1 = i + 3;
27+
}
28+
for (int i = 0; i < n % 3; i++) ans.emplace_back(1, ++n1);
29+
sort(ans.begin(), ans.end());
30+
for (auto [x, y] : ans) cout << x << ' ' << y << endl;
31+
return;
32+
}
33+
34+
int main() {
35+
ios::sync_with_stdio(false), cin.tie(nullptr);
36+
37+
int _;
38+
cin >> _;
39+
while (_--) solve();
40+
return 0;
41+
}

HDOJ/7446.cpp

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
* @file 7446.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2024-07-22
5+
*
6+
* @copyright Copyright (c) 2024
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#define endl '\n'
14+
15+
typedef tuple<int, int, int, int> tiiii;
16+
17+
int f[35][35][2000], id[50][50], X[30], Y[30], A[30], B[30], C[30];
18+
bool vis[35][35][2000];
19+
priority_queue<tiiii, vector<tiiii>, less<tiiii>> que;
20+
21+
void solve(void) {
22+
int n, m, q, d, sx, sy;
23+
cin >> n >> m >> q;
24+
for (int i = 1; i <= n; i++)
25+
for (int j = 1; j <= m; j++) {
26+
id[i][j] = -1;
27+
for (int S = 0; S < (1 << q); S++) f[i][j][S] = -1e9, vis[i][j][S] = false;
28+
}
29+
cin >> d;
30+
for (int i = 0; i < q; i++) cin >> X[i] >> Y[i] >> A[i] >> B[i] >> C[i], id[X[i]][Y[i]] = i;
31+
cin >> sx >> sy;
32+
33+
auto waste = [&](int x, int y, int S) {
34+
int sum = 0;
35+
for (int i = 0; i < q; i++)
36+
if (!(S >> i & 1) && abs(x - X[i]) + abs(y - Y[i]) <= C[i]) sum += B[i];
37+
return sum;
38+
};
39+
40+
que.emplace(f[sx][sy][0] = 0, sx, sy, 0);
41+
while (!que.empty()) {
42+
auto [val, x, y, S] = que.top();
43+
que.pop();
44+
if (vis[x][y][S]) continue;
45+
vis[x][y][S] = true;
46+
for (int tx = x - 1, T = S; tx >= max(1, x - d); tx--) {
47+
int ty = y;
48+
if (id[tx][ty] >= 0 && !(T >> id[tx][ty] & 1))
49+
T |= 1 << id[tx][ty];
50+
else {
51+
int v = val - waste(tx, ty, T);
52+
if (f[tx][ty][T] < v) que.emplace(f[tx][ty][T] = v, tx, ty, T);
53+
}
54+
}
55+
for (int tx = x + 1, T = S; tx <= min(n, x + d); tx++) {
56+
int ty = y;
57+
if (id[tx][ty] >= 0 && !(T >> id[tx][ty] & 1))
58+
T |= 1 << id[tx][ty];
59+
else {
60+
int v = val - waste(tx, ty, T);
61+
if (f[tx][ty][T] < v) que.emplace(f[tx][ty][T] = v, tx, ty, T);
62+
}
63+
}
64+
for (int ty = y - 1, T = S; ty >= max(1, y - d); ty--) {
65+
int tx = x;
66+
if (id[tx][ty] >= 0 && !(T >> id[tx][ty] & 1))
67+
T |= 1 << id[tx][ty];
68+
else {
69+
int v = val - waste(tx, ty, T);
70+
if (f[tx][ty][T] < v) que.emplace(f[tx][ty][T] = v, tx, ty, T);
71+
}
72+
}
73+
for (int ty = y + 1, T = S; ty <= min(m, y + d); ty++) {
74+
int tx = x;
75+
if (id[tx][ty] >= 0 && !(T >> id[tx][ty] & 1))
76+
T |= 1 << id[tx][ty];
77+
else {
78+
int v = val - waste(tx, ty, T);
79+
if (f[tx][ty][T] < v) que.emplace(f[tx][ty][T] = v, tx, ty, T);
80+
}
81+
}
82+
}
83+
int ans = 0;
84+
for (int S = 0; S < (1 << q); S++) {
85+
int delt = 0;
86+
for (int i = 0; i < q; i++)
87+
if (S >> i & 1) delt += A[i];
88+
for (int i = 1; i <= n; i++)
89+
for (int j = 1; j <= m; j++) ans = max(ans, f[i][j][S] + delt);
90+
}
91+
cout << ans << endl;
92+
return;
93+
}
94+
95+
int main() {
96+
ios::sync_with_stdio(false), cin.tie(nullptr);
97+
98+
int _;
99+
cin >> _;
100+
while (_--) solve();
101+
return 0;
102+
}

HDOJ/7447.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* @file 7447.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2024-07-22
5+
*
6+
* @copyright Copyright (c) 2024
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#define endl '\n'
14+
15+
typedef tuple<int, int, int> tiii;
16+
17+
int a[20][20];
18+
19+
vector<tiii> ans;
20+
void chk(int x, int y, int z) {
21+
int t = min({x, y, z});
22+
if (t == y) tie(x, y, z) = make_tuple(y, z, x);
23+
if (t == z) tie(x, y, z) = make_tuple(z, x, y);
24+
if (x == 1) {
25+
if (y == 2 && z == 3) return;
26+
if (y == 3 && z == 4) return;
27+
if (y == 4 && z == 5) return;
28+
if (y == 5 && z == 2) return;
29+
}
30+
if (x == 2) {
31+
if (y == 5 && z == 6) return;
32+
if (y == 6 && z == 3) return;
33+
}
34+
if (x == 3) {
35+
if (y == 6 && z == 4) return;
36+
}
37+
if (x == 4) {
38+
if (y == 6 && z == 5) return;
39+
}
40+
ans.emplace_back(x, min(y, z), max(y, z));
41+
return;
42+
}
43+
44+
void solve(void) {
45+
ans.clear();
46+
for (int i = 1; i <= 9; i++) {
47+
string s;
48+
cin >> s;
49+
for (int j = 1; j <= 12; j++)
50+
if (s[j - 1] == '*')
51+
a[i][j] = -1;
52+
else
53+
a[i][j] = s[j - 1] - '0';
54+
}
55+
chk(a[3][6], a[4][6], a[4][7]);
56+
chk(a[1][6], a[4][9], a[4][10]);
57+
chk(a[1][4], a[4][12], a[4][1]);
58+
chk(a[3][4], a[4][3], a[4][4]);
59+
60+
chk(a[7][4], a[6][4], a[6][3]);
61+
chk(a[9][4], a[6][1], a[6][12]);
62+
chk(a[9][6], a[6][10], a[6][9]);
63+
chk(a[7][6], a[6][7], a[6][6]);
64+
65+
if (ans.empty()) return cout << "No problem" << endl, void();
66+
cout << get<0>(ans.front()) << ' ' << get<1>(ans.front()) << ' ' << get<2>(ans.front()) << endl;
67+
return;
68+
}
69+
70+
int main() {
71+
ios::sync_with_stdio(false), cin.tie(nullptr);
72+
73+
int _;
74+
cin >> _;
75+
while (_--) solve();
76+
return 0;
77+
}

HDOJ/7450.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* @file 7450.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2024-07-22
5+
*
6+
* @copyright Copyright (c) 2024
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#define maxn 100005
14+
#define endl '\n'
15+
16+
struct Frac {
17+
int64_t u, d;
18+
Frac(void) { u = 0, d = 1; }
19+
Frac(int64_t u_, int64_t d_) { u = u_, d = d_; }
20+
Frac operator+(const Frac& o) const {
21+
int64_t ud = d / __gcd(d, o.d) * o.d, uu = ud / d * u + ud / o.d * o.u;
22+
int64_t x = __gcd(ud, uu);
23+
return Frac{uu / x, ud / x};
24+
}
25+
bool operator<(const Frac& o) const {
26+
int64_t ud = d / __gcd(d, o.d) * o.d;
27+
return ud / d * u < ud / o.d * o.u;
28+
}
29+
};
30+
31+
Frac f[maxn];
32+
vector<vector<int>> graph;
33+
34+
void dfs(int p, int pre = -1) {
35+
for (auto i : graph[p])
36+
if (i != pre) f[i] = f[p] + f[i], dfs(i, p);
37+
return;
38+
}
39+
40+
void solve(void) {
41+
int n;
42+
cin >> n;
43+
graph.clear(), graph.resize(n + 1);
44+
for (int i = 1, x, y; i < n; i++) cin >> x >> y, graph[x].push_back(y), graph[y].push_back(x);
45+
for (int i = 1; i <= n; i++) f[i].u = 15, cin >> f[i].d;
46+
dfs(1);
47+
Frac ans(0, 1);
48+
for (int i = 1; i <= n; i++)
49+
if (ans < f[i]) ans = f[i];
50+
cout << ans.u << '/' << ans.d << endl;
51+
return;
52+
}
53+
54+
int main() {
55+
ios::sync_with_stdio(false), cin.tie(nullptr);
56+
57+
int _;
58+
cin >> _;
59+
while (_--) solve();
60+
61+
return 0;
62+
}

HDOJ/7451.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @file 7451.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2024-07-22
5+
*
6+
* @copyright Copyright (c) 2024
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#define endl '\n'
14+
15+
int main() {
16+
ios::sync_with_stdio(false), cin.tie(nullptr);
17+
18+
int _;
19+
cin >> _;
20+
while (_--) {
21+
string s;
22+
cin >> s;
23+
int n = s.size();
24+
s = ' ' + s;
25+
26+
vector<int> pos;
27+
28+
for (int i = 1; i <= n; i++)
29+
if (s[i] == '/') pos.push_back(i);
30+
for (int i = 1; i < pos[0] - 1; i++) cout << s[i];
31+
cout << endl;
32+
for (int i = 1; i + 1 < (int)pos.size(); i++) {
33+
string t;
34+
for (int j = pos[i] + 1; j < pos[i + 1]; j++) t.push_back(s[j]);
35+
int cnt = 0;
36+
for (int j = 1; j + 1 < (int)t.size(); j++)
37+
if (t[j] == '=') cnt++;
38+
if (i != 1 && cnt != 1) continue;
39+
cout << t << endl;
40+
}
41+
}
42+
return 0;
43+
}

0 commit comments

Comments
 (0)