Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5b319b3

Browse files
committed
Today ps
1 parent b67a9c5 commit 5b319b3

File tree

4 files changed

+179
-55
lines changed

4 files changed

+179
-55
lines changed

‎Baekjoon/Cpp/1991.cpp‎

Lines changed: 41 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,62 @@
11
#include <bits/stdc++.h>
22

3-
using ll = long long;
43
using namespace std;
4+
using ll = long long;
5+
using pll = pair<ll, ll>;
56

6-
ll arr[10000];
7-
8-
ll to_ll(char c) {
9-
return ll(c) - 65;
10-
}
7+
struct TreeNode
8+
{
9+
int left;
10+
int right;
1111

12-
voidprint(ll x) {
13-
cout << char(x + 65);
14-
}
12+
TreeNode(int left, int right) : left(left), right(right) {}
13+
};
14+
vector<TreeNode *> tree(26);
1515

16-
void preorder(ll x) {
17-
print(arr[x]);
18-
ll left = x * 2 + 1;
19-
if (arr[left]) {
20-
preorder(left);
21-
}
22-
ll right = x * 2 + 2;
23-
if (arr[right]) {
24-
preorder(right);
16+
void preorder(int node)
17+
{
18+
if (node == -1)
19+
{
20+
return;
2521
}
22+
cout << char(node + 65);
23+
preorder(tree[node]->left);
24+
preorder(tree[node]->right);
2625
}
2726

28-
void inorder(ll x) {
29-
ll left = x * 2 + 1;
30-
if (arr[left]) {
31-
inorder(left);
32-
}
33-
print(arr[x]);
34-
ll right = x * 2 + 2;
35-
if (arr[right]) {
36-
inorder(right);
27+
void inorder(char node)
28+
{
29+
if (node == -1)
30+
{
31+
return;
3732
}
33+
inorder(tree[node]->left);
34+
cout << char(node + 65);
35+
inorder(tree[node]->right);
3836
}
3937

40-
void postorder(ll x) {
41-
ll left = x * 2 + 1;
42-
if (arr[left]) {
43-
postorder(left);
44-
}
45-
ll right = x * 2 + 2;
46-
if (arr[right]) {
47-
postorder(right);
38+
void postorder(int node)
39+
{
40+
if (node == -1)
41+
{
42+
return;
4843
}
49-
print(arr[x]);
44+
postorder(tree[node]->left);
45+
postorder(tree[node]->right);
46+
cout << char(node + 65);
5047
}
5148

52-
int main() {
49+
int main()
50+
{
5351
ios::sync_with_stdio(0);
5452
cin.tie(0);
55-
ll n, i, a, b, c, map[27];
56-
char _a, _b, _c;
53+
int n;
54+
char a, b, c;
5755
cin >> n;
58-
map[0] = 0;
59-
arr[0] = 0;
60-
for (i = 0; i < n; i++) {
61-
cin >> _a >> _b >> _c;
62-
a = to_ll(_a);
63-
if (_b != '.') {
64-
b = to_ll(_b);
65-
map[b] = map[a] * 2 + 1;
66-
arr[map[b]] = b;
67-
}
68-
if (_c != '.') {
69-
c = to_ll(_c);
70-
map[c] = map[a] * 2 + 2;
71-
arr[map[c]] = c;
72-
}
56+
while (n--)
57+
{
58+
cin >> a >> b >> c;
59+
tree[a - 65] = new TreeNode(b == '.' ? -1 : b - 65, c == '.' ? -1 : c - 65);
7360
}
7461
preorder(0);
7562
cout << "\n";

‎Baekjoon/Cpp/24484.cpp‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = long long;
5+
6+
ll cnt, res;
7+
bool vst[100001];
8+
vector<ll> gph[100001];
9+
10+
bool compare(ll a, ll b)
11+
{
12+
return a > b;
13+
}
14+
15+
void dfs(ll x, ll d)
16+
{
17+
if (!vst[x])
18+
{
19+
cnt += 1;
20+
res += cnt * d;
21+
vst[x] = true;
22+
for (ll i : gph[x])
23+
{
24+
dfs(i, d + 1);
25+
}
26+
}
27+
}
28+
29+
int main()
30+
{
31+
ll n, m, r, u, v, i;
32+
cin >> n >> m >> r;
33+
while (m--)
34+
{
35+
cin >> u >> v;
36+
gph[u].push_back(v);
37+
gph[v].push_back(u);
38+
}
39+
for (i = 1; i <= n; i++)
40+
{
41+
sort(gph[i].begin(), gph[i].end(), compare);
42+
}
43+
dfs(r, 0);
44+
cout << res;
45+
return 0;
46+
}

‎Baekjoon/Cpp/9204.cpp‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = long long;
5+
using pll = pair<long, long>;
6+
7+
vector<pll> res;
8+
9+
void bfs(pll s, pll e)
10+
{
11+
queue<vector<pll>> que;
12+
vector<pll> c;
13+
pll cr;
14+
ll i, j;
15+
que.push({s});
16+
while (!que.empty())
17+
{
18+
c = que.front();
19+
que.pop();
20+
cr = c[c.size() - 1];
21+
if (cr.first == e.first && cr.second == e.second)
22+
{
23+
res = c;
24+
break;
25+
}
26+
for (i = cr.first, j = cr.second; i < 9 && j < 9; i += !!(j++))
27+
{
28+
c.push_back({i, j});
29+
que.push(c);
30+
c.pop_back();
31+
}
32+
for (i = cr.first - 1, j = cr.second - 1; i > 0 && j > 0; i -= !!(j--))
33+
{
34+
c.push_back({i, j});
35+
que.push(c);
36+
c.pop_back();
37+
}
38+
for (i = cr.first, j = cr.second; i < 9 && j > 0; i += !!(j--))
39+
{
40+
c.push_back({i, j});
41+
que.push(c);
42+
c.pop_back();
43+
}
44+
for (i = cr.first - 1, j = cr.second + 1; i > 0 && j < 9; i -= !!(j++))
45+
{
46+
c.push_back({i, j});
47+
que.push(c);
48+
c.pop_back();
49+
}
50+
}
51+
}
52+
53+
int main()
54+
{
55+
ios::sync_with_stdio(0);
56+
cin.tie(0);
57+
ll t, i, x1, x2, y1, y2;
58+
char c;
59+
cin >> t;
60+
while (t--)
61+
{
62+
cin >> c;
63+
x1 = c - 64;
64+
cin >> y1;
65+
y1 = 9 - y1;
66+
cin >> c;
67+
x2 = c - 64;
68+
cin >> y2;
69+
y2 = 9 - y2;
70+
if (abs(x1 - x2) % 2 == abs(y1 - y2) % 2)
71+
{
72+
bfs({x1, y1}, {x2, y2});
73+
}
74+
if (res.empty())
75+
{
76+
cout << "Impossible";
77+
}
78+
else
79+
{
80+
cout << res.size() - 1;
81+
for (i = 0; i < res.size(); i++)
82+
{
83+
cout << " " << char(res[i].first + 64) << " " << 9 - res[i].second;
84+
}
85+
res.clear();
86+
}
87+
cout << "\n";
88+
}
89+
return 0;
90+
}

‎templates/example.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include <bits/stdc++.h>
22

3-
using ll = long long;
43
using namespace std;
4+
using ll = long long;
5+
using pll = pair<ll, ll>;
56

67
int main() {
78
ios::sync_with_stdio(0);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /