Những câu hỏi liên quan
Tiếng anh123456
Xem chi tiết
Nguyễn Hoàng Duy
12 tháng 8 2023 lúc 14:49

Tham Khảo:

#include <bits/stdc++.h>

using namespace std;

bool v(int y, int x) {

return 1 <= y && y <= 8 && 1 <= x && x <= 8;

}

int m(int y, int x, int ty, int tx) {

if (!v(y, x) || !v(ty, tx)) {

return -1;

}

deque<pair<int, pair<int, int>>> q;

q.push_back({y, {x, 0}});

bool vis[9][9] = {false};

vis[y][x] = true;

int dx[] = {-2, -2, 2, 2};

int dy[] = {-2, 2, -2, 2};

while (!q.empty()) {

int cy = q.front().first;

int cx = q.front().second.first;

int s = q.front().second.second;

q.pop_front();

if (cy == ty && cx == tx) {

return s;

}

for (int i = 0; i < 4; ++i) {

int ny = cy + dy[i];

int nx = cx + dx[i];

if (v(ny, nx) && !vis[ny][nx]) {

q.push_back({ny, {nx, s + 1}});

vis[ny][nx] = true;

        }

    }

}

return -1;

}

int main() {

int y, x, ty, tx;

cin >> y >> x >> ty >> tx;

cout << m(y, x, ty, tx) << endl;

return 0;

}

Bình luận (0)
Khánh Hằng Mai
Xem chi tiết
Nguyễn Minh Lệ
9 tháng 11 2023 lúc 21:46

#include<iostream>

using namespace std;

int main() {

int a,b;

cin >> a >> b;

cout << (a+b)*2;

return 0;

}

Bình luận (0)
Tú Nguyễn
28 tháng 9 2020 lúc 17:43
#include <iostream.h> int main() { float a,b,cv; cout <<"Nhap a:"; cin >> a; cout <<"Nhap b:"; cin >> b; if ((a>=1)&&(a<=100)&&(b>=1)&&(b<=100)) { cv = (a+b)*2; cout <<" Chu vi hcn la: "<<cv<<endl; } }
Bình luận (0)
 Khách vãng lai đã xóa
Tú Nguyễn
28 tháng 9 2020 lúc 17:44

Bình luận (0)
Nguyễn Chơn Nhân
Xem chi tiết
Nguyễn Lê Phước Thịnh
26 tháng 11 2019 lúc 22:12

uses crt;
const fi='standard.inp';
fo='standard.out';
var f1,f2:text;
a:array[1..100]of integer;
i,j,n,dem,t:integer;
begin
clrscr;
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n);
for i:=1 to n do
readln(f1,a[i]);
{--------------------xu-ly------------------}
for i:=1 to n do
begin
write(f2,a[i],' co so uoc la: ');
dem:=0;
t:=0;
for j:=1 to a[i] do
if a[i] mod j=0 then
begin
dem:=dem+1;
t:=t+j;
end;
writeln(f2,dem.,' tong uoc la: ',t);
end;
close(f1);
close(f2);
readln;
end.

Bình luận (0)
 Khách vãng lai đã xóa
Tuyết hoàng thị
11 tháng 8 2021 lúc 9:36

var n:qword;i:longint;
a:array[1..1000] of longint;
function du(x:qword):qword;
var k,d:longint;
begin
d:=0;
for k:=1 to trunc(sqrt(x)) do
 begin
  if x mod k=0 then
   begin
    d:=d+2;
   end;
 end;
if sqrt(x)=trunc(sqrt(x)) then dec(d);
du:=d;
end;
function tu(s:qword):qword;
var t:qword;j:longint;
begin
t:=0;
for j:=1 to trunc(sqrt(s)) do
  if s mod j=0 then t:=t+j+(s div j);
tu:=t;
end;
begin
readln(n);
for i:=1 to n do
  readln(a[i]);
for i:=1 to n do
 writeln(a[i],' co ',du(a[i]),' uoc. Tong uoc la: ',tu(a[i]));
readln;
end.

Bình luận (0)
Gia Bảo Huỳnh
Xem chi tiết
Hiếu Phí Lê
Xem chi tiết
Thanh Bình
Xem chi tiết
Gia Huy
27 tháng 6 2023 lúc 17:40

```python
n = int(input())
p = list(map(int, input().split()))

pos = [0] * n
for i in range(n):
pos[p[i]-1] = i

count = 0
for i in range(n):
if pos[i] != i:
j = pos[i]
pos[i], pos[j] = pos[j], pos[i]
count += 1

print(count)
```

Bình luận (0)
Thanh Bình
27 tháng 6 2023 lúc 16:46

Pascal, c++ hay python gì cũng được

Bình luận (0)
Thanh Bình
Xem chi tiết
Nguyễn Hoàng Duy
27 tháng 6 2023 lúc 16:57

def exchange(n, memo):
    if n in memo:
        return memo[n]
    if n == 0:
        return 0
    max_exchange = max(n, exchange(n // 2, memo) + exchange(n // 3, memo) + exchange(n // 4, memo))
    memo[n] = max_exchange
    return max_exchange

while True:
    try:
        n = int(input())
        memo = {}
        print(exchange(n, memo))
    except:
        break
    

Bình luận (0)
Nhung
Xem chi tiết
pthaokuche
Xem chi tiết
Nguyễn Lê Phước Thịnh
13 tháng 11 2021 lúc 0:16

uses crt;

var a,b:longint;

begin

clrscr;

readln(a,b);

writeln(a*b);

readln;

end.

Bình luận (0)