Tên đăng nhập Điểm ▾ Bài tập Giới thiệu
41501
24MTTN210
Nguyễn Đức Anh Khoa
0 0
41501
24MTTN211
Trần Tiến Khoa
0 0
41501
24MTTN212
Lê Hoàng Long
0 0
41501
24MTTN213
Nguyễn Duy Nguyên
0 0
41501 0 0
41501 0 0

include <iostream>

include <vector>

include <queue>

include <stack>

using namespace std;

const int MAX = 1003;
int n, m;
vector<string> maze(MAX);
vector<vector\<int>> distA(MAX, vector<int>(MAX, -1));
vector<vector\<int>> distM(MAX, vector<int>(MAX, -1));
vector<pair\<int, int>> monsters;
pair<int, int> start;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
char dir[4] = {'D', 'U', 'R', 'L'};

bool isValid(int x, int y) {
return x >= 0 && x < n && y >= 0 && y < m && maze[x][y] != '#';
}

void bfs(queue<pair\<int, int>>& q, vector<vector\<int>>& dist) {
while (!q.empty()) {
auto [x, y] = q.front(); q.pop();
for (int i = 0; i < 4; i++) {
int nx = x + dx[i], ny = y + dy[i];
if (isValid(nx, ny) && dist[nx][ny] == -1) {
dist[nx][ny] = dist[x][y] + 1;
q.push({nx, ny});
}
}
}
}

int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> maze[i];
}

queue<pair<int, int>> q;
for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
        if (maze[i][j] == 'A') {
            start = {i, j};
            distA[i][j] = 0;
        } else if (maze[i][j] == 'M') {
            monsters.push_back({i, j});
            distM[i][j] = 0;
            q.push({i, j});
        }
    }
}

bfs(q, distM);  // BFS for monsters

q.push(start);
bfs(q, distA);  // BFS for player

vector<vector<int>> exitDist = distA;
for (auto [x, y] : monsters) {
    if (distA[x][y] != -1 && distA[x][y] <= distM[x][y]) {
        cout << "NO" << endl;
        return 0;
    }
}

int ex = -1, ey = -1;
for (int i = 0; i < n; i++) {
    if (maze[i][0] == '.' || maze[i][0] == 'A') {
        if (distA[i][0] != -1 && (distA[i][0] < distM[i][0] || distM[i][0] == -1)) {
            ex = i, ey = 0;
            break;
        }
    }
    if (maze[i][m-1] == '.' || maze[i][m-1] == 'A') {
        if (distA[i][m-1] != -1 && (distA[i][m-1] < distM[i][m-1] || distM[i][m-1] == -1)) {
            ex = i, ey = m-1;
            break;
        }
    }
}
for (int j = 0; j < m; j++) {
    if (maze[0][j] == '.' || maze[0][j] == 'A') {
        if (distA[0][j] != -1 && (distA[0][j] < distM[0][j] || distM[0][j] == -1)) {
            ex = 0, ey = j;
            break;
        }
    }
    if (maze[n-1][j] == '.' || maze[n-1][j] == 'A') {
        if (distA[n-1][j] != -1 && (distA[n-1][j] < distM[n-1][j] || distM[n-1][j] == -1)) {
            ex = n-1, ey = j;
            break;
        }
    }
}

if (ex == -1) {
    cout << "NO" << endl;
    return 0;
}

cout << "YES" << endl;
vector<char> path;
while (ex != start.first || ey != start.second) {
    for (int i = 0; i < 4; i++) {
        int nx = ex - dx[i], ny = ey - dy[i];
        if (isValid(nx, ny) && distA[nx][ny] == distA[ex][ey] - 1) {
            path.push_back(dir[i]);
            ex = nx;
            ey = ny;
            break;
        }
    }
}
reverse(path.begin(), path.end());
cout << path.size() << endl;
for (char c : path) cout << c;
cout << endl;

return 0;

}

41501 0 0
41501 0 0
41501 0 0
41501
nvannam
nvannam
0 0
41501 0 0
41501 0 0
41501 0 0
41501
maihuyen235_cva
huyena235-CVA
0 0
41501
hoangnhatthinh
hoangnhatthinh
0 0
41501 0 0

HI=>

41501 0 0
41501 0 0
41501 0 0
41501 0 0

include <bits/stdc++.h>

using namespace std;
int n, b,c,d,S;
float a;
int main()
{
cin >> n;
a = (sqrt(1+8n)-1)/2;
if ( a == int(a))
a = a;
else
a = a+1;
b = (a
a+a)/2;
c = b - n;
d = (a(a+1)(2a+1))/6;
S = d - c
a;

cout << S;

return 0;

}

41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501
kevinvladimirnomnom
Nguyễn Thành Vinh
0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0

include <iostream>

include <math.h>

using namespace std;
int main() {
unsigned long long l, r, a[100];
cin>>l>>r;
int i=0, luy_thua=1; a[0]=1;
while (luy_thua<=r) {
i++; luy_thua=2;
a[i]=luy_thua;
}
int max=0, dmax=1;
for (int j=l; j<=floor(sqrt(r)); j++) {
int k=0;
while (a[k]
j<=r) k++;
if (k>max) {
max=k;
dmax=1;
}
else if (k=max) dmax++;
}
cout<<max<<' '<<dmax;
}

41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0

include <iostream>

using namespace std;

int main (){
int i;
cin >> a >> b >> c;
cout << "Điểm trung bình 3 môn:" << ((a + b + c)/3) << setprecision (2);
if (int i >= 0 && i>= 10) {
exit();
}
return 0;
}

41501 0 0
41501 0 0
41501
pntho1502 1367
Phạm Ngọc Thơ
0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501
kokominosimp 1002
Bùi Đăng Toán
0 0

Wibijack

41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0
41501 0 0