Skip to content

Commit b648242

Browse files
committed
y
1 parent a28e113 commit b648242

19 files changed

+483
-1
lines changed

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"fstream": "cpp",
4444
"limits": "cpp",
4545
"sstream": "cpp",
46-
"typeinfo": "cpp"
46+
"typeinfo": "cpp",
47+
"queue": "cpp"
4748
}
4849
}

1600

32.1 KB
Binary file not shown.

1600.cpp

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include <iostream>
2+
#include <queue>
3+
using namespace std;
4+
typedef long long ll;
5+
6+
struct Node
7+
{
8+
int x, y, z, count;
9+
};
10+
11+
int xxxx[] = {-1, 0, 1, 0};
12+
int yyyy[] = {0, 1, 0, -1};
13+
14+
void solve()
15+
{
16+
int N, M, K;
17+
cin >> K >> M >> N;
18+
int map[N][M];
19+
for (int i = 0; i < N; i++)
20+
for (int j = 0; j < M; j++)
21+
cin >> map[i][j];
22+
23+
int counts[N][M][K + 1];
24+
for (int i = 0; i < N; i++)
25+
for (int j = 0; j < M; j++)
26+
for (int k = 0; k <= K; k++)
27+
counts[i][j][k] = 1e9;
28+
29+
queue<Node> q;
30+
q.push({0, 0, 0, 0});
31+
while (q.size())
32+
{
33+
auto [x, y, z, count] = q.front();
34+
if (x == N - 1 && y == M - 1)
35+
{
36+
cout << count;
37+
return;
38+
}
39+
int next_count = count + 1;
40+
q.pop();
41+
42+
for (int i = 0; i < 4; i++)
43+
{
44+
int next_x = x + xxxx[i];
45+
int next_y = y + yyyy[i];
46+
if (next_x < 0 || next_y < 0 || next_x >= N || next_y >= M || map[next_x][next_y] == 1)
47+
continue;
48+
if (counts[next_x][next_y][z] <= next_count)
49+
continue;
50+
counts[next_x][next_y][z] = next_count;
51+
q.push({next_x, next_y, z, next_count});
52+
}
53+
if (z + 1 <= K)
54+
{
55+
int xxxxxxxx[] = {-1, -2, -2, -1, 1, 2, 2, 1};
56+
int yyyyyyyy[] = {-2, -1, 1, 2, 2, 1, -1, -2};
57+
for (int i = 0; i < 8; i++)
58+
{
59+
int next_x = x + xxxxxxxx[i];
60+
int next_y = y + yyyyyyyy[i];
61+
int next_z = z + 1;
62+
if (next_x < 0 || next_y < 0 || next_x >= N || next_y >= M || map[next_x][next_y] == 1)
63+
continue;
64+
if (counts[next_x][next_y][next_z] <= next_count)
65+
continue;
66+
counts[next_x][next_y][next_z] = next_count;
67+
q.push({next_x, next_y, next_z, next_count});
68+
}
69+
}
70+
}
71+
cout << -1;
72+
}
73+
int main()
74+
{
75+
cin.tie(0)->sync_with_stdio(false);
76+
solve();
77+
return 0;
78+
}

16933

34.6 KB
Binary file not shown.

16933.cpp

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include <iostream>
2+
#include <queue>
3+
#include <string>
4+
using namespace std;
5+
typedef long long ll;
6+
7+
struct Node
8+
{
9+
int x, y, z, day, count;
10+
};
11+
12+
int xxxx[] = {-1, 0, 1, 0};
13+
int yyyy[] = {0, 1, 0, -1};
14+
15+
void solve()
16+
{
17+
int N, M, K;
18+
cin >> N >> M >> K;
19+
string map[N];
20+
for (int i = 0; i < N; i++)
21+
cin >> map[i];
22+
23+
int counts[N][M][K + 1][2];
24+
for (int i = 0; i < N; i++)
25+
for (int j = 0; j < M; j++)
26+
for (int k = 0; k <= K; k++)
27+
counts[i][j][k][0] = counts[i][j][k][1] = 1e9;
28+
29+
queue<Node> q;
30+
q.push({0, 0, 0, 0, 1});
31+
while (q.size())
32+
{
33+
auto [x, y, z, day, count] = q.front();
34+
q.pop();
35+
36+
if (x == N - 1 && y == M - 1)
37+
{
38+
cout << count;
39+
return;
40+
}
41+
42+
for (int i = 0; i < 4; i++)
43+
{
44+
int next_x = x + xxxx[i];
45+
int next_y = y + yyyy[i];
46+
int next_z = z;
47+
int next_count = count + 1;
48+
int next_day = (day + 1) % 2;
49+
if (next_x < 0 || next_y < 0 || next_x >= N || next_y >= M)
50+
continue;
51+
if (map[next_x][next_y] == '1')
52+
{
53+
if (next_day)
54+
next_z++;
55+
else
56+
{
57+
next_x -= xxxx[i];
58+
next_y -= yyyy[i];
59+
}
60+
if (next_z > K)
61+
continue;
62+
}
63+
64+
if (counts[next_x][next_y][next_z][next_day] <= next_count)
65+
continue;
66+
counts[next_x][next_y][next_z][next_day] = next_count;
67+
q.push({next_x, next_y, next_z, next_day, next_count});
68+
}
69+
}
70+
cout << -1;
71+
}
72+
int main()
73+
{
74+
cin.tie(0)->sync_with_stdio(false);
75+
solve();
76+
return 0;
77+
}

17071

45.8 KB
Binary file not shown.

17103

12.9 KB
Binary file not shown.

17103.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <iostream>
2+
using namespace std;
3+
typedef long long ll;
4+
5+
bool is_prime[1000001];
6+
int main()
7+
{
8+
cin.tie(0)->sync_with_stdio(false);
9+
for (int i = 2; i <= 1000000; i++)
10+
is_prime[i] = true;
11+
for (int i = 2; i <= 1000000; i++)
12+
{
13+
if (is_prime[i])
14+
for (int j = i + i; j <= 1000000; j += i)
15+
{
16+
is_prime[j] = false;
17+
}
18+
}
19+
20+
int t;
21+
cin >> t;
22+
while (t--)
23+
{
24+
int z;
25+
cin >> z;
26+
int count = 0;
27+
for (int i = 2; i < z; i++)
28+
{
29+
if (z - i >= i && is_prime[i] && is_prime[z - i])
30+
count++;
31+
}
32+
cout << count << '\n';
33+
}
34+
return 0;
35+
}

2146

28.2 KB
Binary file not shown.

2146.cpp

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#include <iostream>
2+
#include <queue>
3+
#include <algorithm>
4+
using namespace std;
5+
typedef long long ll;
6+
7+
int arr[101][101], N;
8+
int xxxx[] = {-1, 0, 1, 0};
9+
int yyyy[] = {0, 1, 0, -1};
10+
int m = 2;
11+
void dfs(int x, int y)
12+
{
13+
if (x < 0 || y < 0 || x >= N || y >= N || arr[x][y] != 1)
14+
return;
15+
16+
arr[x][y] = m;
17+
for (int i = 0; i < 4; i++)
18+
dfs(x + xxxx[i], y + yyyy[i]);
19+
}
20+
21+
struct Node
22+
{
23+
int x, y, count;
24+
};
25+
26+
void solve()
27+
{
28+
cin >> N;
29+
for (int i = 0; i < N; i++)
30+
for (int j = 0; j < N; j++)
31+
cin >> arr[i][j];
32+
33+
for (int i = 0; i < N; i++)
34+
{
35+
for (int j = 0; j < N; j++)
36+
{
37+
if (arr[i][j] != 1)
38+
continue;
39+
dfs(i, j);
40+
m++;
41+
}
42+
}
43+
44+
int result = 9999999;
45+
for (int i = 2; i < m; i++)
46+
{
47+
int counts[N][N];
48+
for (int j = 0; j < N; j++)
49+
for (int k = 0; k < N; k++)
50+
counts[j][k] = 9999999;
51+
52+
queue<Node> q;
53+
54+
for (int j = 0; j < N; j++)
55+
for (int k = 0; k < N; k++)
56+
if (arr[j][k] == i)
57+
{
58+
counts[j][k] = 0;
59+
q.push({j, k, 0});
60+
}
61+
62+
while (q.size())
63+
{
64+
auto [x, y, count] = q.front();
65+
q.pop();
66+
67+
for (int i = 0; i < 4; i++)
68+
{
69+
int next_x = x + xxxx[i];
70+
int next_y = y + yyyy[i];
71+
int next_count = count + 1;
72+
73+
if (next_x < 0 || next_y < 0 || next_x >= N || next_y >= N || arr[next_x][next_y] == i || counts[next_x][next_y] <= next_count)
74+
continue;
75+
if (arr[next_x][next_y] > 1)
76+
{
77+
result = min(result, count);
78+
continue;
79+
}
80+
81+
counts[next_x][next_y] = next_count;
82+
q.push({next_x, next_y, next_count});
83+
}
84+
}
85+
}
86+
87+
cout << result;
88+
}
89+
int main()
90+
{
91+
cin.tie(0)->sync_with_stdio(false);
92+
solve();
93+
return 0;
94+
}

2312

12.9 KB
Binary file not shown.

2312.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
using namespace std;
4+
typedef long long ll;
5+
6+
void solve()
7+
{
8+
int N;
9+
cin >> N;
10+
11+
int count = 0;
12+
for (int i = 2; i <= 100000; i++)
13+
{
14+
if (N % i == 0)
15+
{
16+
count++;
17+
N /= i;
18+
i--;
19+
continue;
20+
}
21+
else
22+
{
23+
if (count)
24+
{
25+
cout << i << ' ' << count << '\n';
26+
}
27+
count = 0;
28+
}
29+
}
30+
}
31+
32+
int main()
33+
{
34+
cin.tie(0)->sync_with_stdio(false);
35+
int T;
36+
cin >> T;
37+
while (T--)
38+
solve();
39+
return 0;
40+
}

4796

13.1 KB
Binary file not shown.

4796.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
using namespace std;
4+
typedef long long ll;
5+
6+
int r = 0;
7+
bool solve()
8+
{
9+
r++;
10+
ll x, y, z;
11+
cin >> x >> y >> z;
12+
if (x + y + z == 0)
13+
return false;
14+
15+
cout << "Case " << r << ": " << (z / y * x + min(z % y, x)) << '\n';
16+
17+
return true;
18+
}
19+
20+
int main()
21+
{
22+
cin.tie(0)->sync_with_stdio(false);
23+
while (solve())
24+
;
25+
return 0;
26+
}

6593

38.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)