Yêu cầu: Tính chu vi của HCN
Dữ liệu: a, b là độ dài chiều dài và chiều rộng của HCN (1<=a,b<=100)
Kết quả: Chu vi HCN đó.
Ví dụ input 1115 output 52
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;
}
N0522B - Biến đổi ma trận 2
Dữ liệu vào: standard input
Dữ liệu ra: standard output
Giới hạn thời gian: 1.0 giây
Giới hạn bộ nhớ: 128 megabyte
Đăng bởi: hienht
Yêu cầu: Viết chương trình nhập vào một ma trận vuông. In ra ma trận sau khi xoay nó 1 góc 90 độ theo chiều kim đồng hồ.
Dữ liệu:
- Dòng đầu tiên ghi số nguyên không âm n(n <= 100),
- n dòng sau, mỗi dòng ghi n số nguyên biểu diễn hàng thứ i của ma trận.
Kết quả: In ra ma trận sau khi xoay
Ví dụ
input
4
1 2 4 4
3 3 1 1
4 4 5 4
4 2 5 1
output
4 4 3 1
2 4 3 2
5 5 1 4
1 4 1 4
ngôn ngữ c++
giúp mik với
Tính tổng các ước của số nguyên dương n (n ≤ 10^12).
Dữ liệu nhập:
- Dòng đầu chứa số bộ test.
- Các dòng sau, mỗi dòng chứa 1 số nguyên dương n (n ≤ 10^12).
Kết quả:
- Mỗi test in trên 1 dòng chứa 1 số nguyên là tổng các ước của test tương ứng.
Ví dụ input 3uses 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.
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.
Cho 2 số nguyên dương a và N (a<= 100; N<=106)
Tìm chữ số tận cùng của aN
Dữ liệu vào:
2 số a và N cách nhau 1 khoảng trắng.
Kết quả:
1 số duy nhất là kết quả tìm được
Ví dụinput
2 5
output
2
Giải thích ví dụ: 2 mũ 5 là 32, chữ số tận cùng của 32 là 2
Bài này bạn cũng có thể chuyển qua xâu để xử lý.
DPRCCOI - ĐỔI TIỀN
Dữ liệu vào: standard input
Dữ liệu ra: standard output
Giới hạn thời gian: 1.0 giây
Giới hạn bộ nhớ: 128 megabyte
Ở AnLuuLand họ có một hệ thống tiền tệ rất kỳ lạ. Mỗi đồng tiền vàng của AnLuuLand có một số nguyên được viết trên đó. Một đồng n có thể được trao đổi trong ngân hàng thành ba đồng tiền: n div 2, n div 3 và n div 4.
Bạn cũng có thể đổi tiền AnLuuLand thành đô la Mỹ. Tỷ giá hối đoái là 1:1. Nhưng bạn không thể mua tiền AnLuuLand.
Bạn có đồng vàng ghi số n. Số đô la Mỹ tối đa bạn có thể đổi được là bao nhiêu?
Dữ liệu nhập:
- Dữ liệu nhập: sẽ chứa một số trường hợp thử nghiệm (không quá 10).
- Mỗi testcase là một dòng duy nhất có số n (0 ≤ n ≤ 109). Đó là số được viết trên đồng tiền của bạn.
Kết quả:
- Đối với mỗi trường hợp thử nghiệm xuất ra một dòng duy nhất, chứa số đô la Mỹ tối đa bạn có thể kiếm được.
Ví dụ
input
0
1
2
3
4
5
12
32
12345
7985
1000000000
output
0
1
2
3
4
5
13
35
21629
13137
4243218150
Chú thích:
- Bạn có thể thay đổi 12 thành 6, 4 và 3, sau đó đổi chúng thành $6 + $4 + $3 = $13.
- Nếu bạn thử đổi xu 2 thành 3 đồng xu nhỏ hơn, bạn sẽ nhận được 1, 0 và 0, và sau đó bạn có thể nhận được không quá 1 đô la trong số đó. Tốt hơn là chỉ cần thay đổi 2 đồng tiền trực tiếp thành 2 đô la.
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
TUVUNG - TỪ VỰNG
Dữ liệu vào: standard input
Dữ liệu ra: standard output
Giới hạn thời gian: 1.0 giây
Giới hạn bộ nhớ: 128 megabyte
Uyên viết ra một xâu S có độ dài không quá 106 chỉ gồm các kí tự thường trong bảng chữ cái tiếng Anh. Một từ vựng là một từ thu được bằng cách sao chép một đoạn kí tự liên tiếp từ xâu S thoả mãn một trong hai điều kiện:
- Bắt đầu bằng một nguyên âm (a, e, i, o, u), kết thúc bằng một phụ âm
- bắt đầu bằng một phụ âm và kết thúc là một nguyên âm.
Yêu cầu: Giúp Uyên đếm số lượng từ vựng có trong S theo quy tắc trên.
Dữ liệu nhập:
- Gồm một xâu S.
Kết quả:
- in ra một số duy nhất là kết quả tìm được.
Ràng buộc:
- 1/3 số test: Xâu S dài không quá 104.
Ví dụ
input
adceba
output
9
Lưu ý:
- Đây không phải là test chấm chính thức của BTC.
GRETRAINS - SẮP XẾP TÀU
Dữ liệu vào: standard input
Dữ liệu ra: standard output
Giới hạn thời gian: 1.0 giây
Giới hạn bộ nhớ: 128 megabyte
Một tuyến đường sắt dài vô tận có một đoàn tàu gồm n toa tàu được đánh số từ 1 đến n (số của tất cả các toa là khác biệt) và được định vị theo thứ tự tùy ý. Huy muốn sắp xếp chiếc xe lửa theo thứ tự tăng dần của các toa tàu.
Trong một lần di chuyển, anh ta có thể làm cho một trong những toa tàu biến mất khỏi vị trí của nó và dịch chuyển nó đến đầu tàu, hoặc đến cuối tàu theo mong muốn của anh ta. Số lượng hành động tối thiểu Huy cần thực hiện để sắp xếp tàu là bao nhiêu?
Dữ liệu nhập:
- Dòng đầu tiên của đầu vào chứa số nguyên n (1 ≤ n ≤ 100 000 ) - số lượng toa tàu trong xe lửa.
- Dòng thứ hai chứa n số nguyên pi ( 1 ≤ pi ≤ n , pi ≠ pj nếu i ≠ j ) - dãy số của các toa tàu trong tàu.
Kết quả:
- in một số nguyên duy nhất - số lượng hành động tối thiểu cần thiết để sắp xếp các toa xe lửa.
Ví dụ
input
5
4 1 2 5 3
output
2
input
4
4 1 3 2
output
2
```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)
```
SHCN - Diện tích HCN
Dữ liệu vào: standard input
Dữ liệu ra: standard output
Giới hạn thời gian: 1.0 giây
Giới hạn bộ nhớ: 128 megabyte
Đăng bởi: phuleethanh
Lập trình tính và thông báo ra màn hình diện tích hình chữ nhật với hai cạnh a và b là các số nguyên được nhập vào từ bàn phím (1 ≤ a,b ≤ 106)?
Ví dụ
input
92 82
output
7544
dùng ngôn ngữ free pascal
giúp mình với ạ
uses crt;
var a,b:longint;
begin
clrscr;
readln(a,b);
writeln(a*b);
readln;
end.