A
Đề bài yêu cầu xác định hai chuỗi có phải là "AtCoder" và "Land" hay không, phân biệt chữ hoa chữ thường.
<?cpp
#include <iostream>
using namespace std;
string str1, str2;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> str1 >> str2;
if (str1 == "AtCoder" && str2 == "Land") cout << "Yes\n";
else cout << "No\n";
return 0;
}
?>
B
Mỗi người mất A giây để mua vé. Nếu có người xếp hàng trước đó thì người tiếp theo sẽ bắt đầu mua vé ngay khi người trước hoàn thành. Tìm thời gian hoàn thành mua vé cho mỗi người.
<?cpp
#include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int N, A, currentTime = 0;
cin >> N >> A;
for(int i = 0; i < N; ++i) {
int arrivalTime;
cin >> arrivalTime;
if(arrivalTime >= currentTime)
currentTime = arrivalTime + A;
else
currentTime += A;
cout << currentTime << "\n";
}
return 0;
}
?>
C
Có n cửa hàng và m loại sản phẩm. Mỗi cửa hàng được biểu diễn bằng một chuỗi dài m, với 'o' nếu cửa hàng bán sản phẩm đó, 'x' nếu không. Cần tìm số lượng cửa hàng tối thiểu cần ghé thăm để mua đủ tất cả các sản phẩm.
<?cpp
#include <iostream>
#include <bitset>
using namespace std;
const int MAX = 15;
string shops[MAX];
int minShops = MAX, N, M;
void dfs(int idx, bitset<MAX> products, int count) {
if (products.count() == M) {
minShops = min(minShops, count);
return;
}
if (idx >= N) return;
bitset<MAX> tempProducts = products;
for (int j = 0; j < M; ++j) {
if (shops[idx][j] == 'o') tempProducts[j] = 1;
}
dfs(idx + 1, products, count);
dfs(idx + 1, tempProducts, count + 1);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N >> M;
for (int i = 0; i < N; ++i) cin >> shops[i];
dfs(0, bitset<MAX>(), 0);
cout << (minShops == MAX ? -1 : minShops) << "\n";
return 0;
}
?>
D
Tìm hộp quà sao cho tổng giá trị của chúng nhỏ nhất mà vẫn thỏa mãn điều kiện về số lượng kẹo trong mỗi hộp.
<?cpp
#include <iostream>
#include <algorithm>
using namespace std;
int A[200005], B[200005], totalCost = 0;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int N, M;
cin >> N >> M;
for (int i = 0; i < N; ++i) cin >> A[i];
for (int i = 0; i < M; ++i) cin >> B[i];
sort(A, A + N);
sort(B, B + M);
int aIdx = 0, bIdx = 0;
while (bIdx < M) {
bool found = false;
while (aIdx < N && A[aIdx] < B[bIdx]) ++aIdx;
if (aIdx < N) {
totalCost += A[aIdx++];
++bIdx;
found = true;
}
if (!found) {
cout << "-1\n";
return 0;
}
}
cout << totalCost << "\n";
return 0;
}
?>
G
Tìm cách di chuyển tối ưu trên lưới để đạt tổng giá trị lớn nhất sau K bước, có thể đứng yên tại một ô.
<?cpp
#include <iostream>
#include <cstring>
using namespace std;
const int INF = 1e9;
int grid[305][305], dp[305][305][305];
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
int maxScore = -INF;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int H, W, K, startX, startY;
cin >> H >> W >> K >> startX >> startY;
for (int i = 1; i <= H; ++i)
for (int j = 1; j <= W; ++j)
cin >> grid[i][j];
memset(dp, -0x3f, sizeof(dp));
dp[0][startX][startY] = 0;
for (int step = 1; step <= K; ++step) {
for (int x = 1; x <= H; ++x)
for (int y = 1; y <= W; ++y) {
for (int dir = 0; dir < 4; ++dir) {
int nx = x + dx[dir], ny = y + dy[dir];
if (nx > 0 && nx <= H && ny > 0 && ny <= W)
dp[step][x][y] = max(dp[step][x][y], dp[step-1][nx][ny] + grid[x][y]);
}
maxScore = max(maxScore, dp[step][x][y] + (K - step) * grid[x][y]);
}
}
cout << maxScore << "\n";
return 0;
}
?>