Bài viết 88king Vin liên quan

s6666 đăng nhập,cổng game đổi thưởng tặng tiền khi đăng ký,Rik66 Club Game Bài Zic

Hướng dẫn giải bài tập ACM Hrbust Tuần 1-2 năm 2024

Tác giả: HowieHz
Ngày viết: 02/09/2024

Danh mục: Chia sẻ kiến thức > Giải thuật thi đấu > Lưu trữ đề giải

🌍 Tiếng Việt

Số lượt xem: 181


  • Tổng hợp các bài viết về luyện tập giải thuật

Lời mở đầu

Liên kết đề bài: Đề bài tuần 1-2 cho sinh viên khóa 2024

Qua hai tuần làm quen với hệ thống OJ, chúng ta nhận thấy rằng Vjudge không được tiện lợi như LOJ (LuoGu). Một điểm hạn chế là trình soạn thảo mã nguồn khi submit thiếu tính năng tô sáng cú pháp.

Trong phần này, tôi sẽ cung cấp mã nguồn Python3 trước và sau đó là C++. Hãy chú ý đến phạm vi dữ liệu của từng bài toán, một số bài cần sử dụng kiểu dữ liệu long long.


Bài A

Mã nguồn Python:

1
print("Hello World!")

Mã nguồn C++:

1
2
3
4
5
6
#include <bits/stdc++.h>
using namespace std;
int main(){
    cout << "Hello World!";
    return 0;
}

Bài B

Mã nguồn Python:

1
print(chr(int(input())))

Mã nguồn C++:

1
2
3
4
5
6
7
8
#include <bits/stdc++.h>
using namespace std;
int main(){
    int ch;
    cin >> ch;
    cout << static_cast<char>(ch);
    return 0;
}

Bài C

Mã nguồn Python:

1
print(sum(map(int, input().split())))

Mã nguồn C++:

1
2
3
4
5
6
7
8
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    cout << a + b;
    return 0;
}

Bài D

Mã nguồn Python:

1
print(int(input()) ** 2)

Mã nguồn C++:

1
2
3
4
5
6
7
8
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long a;
    cin >> a;
    cout << a * a;
    return 0;
}

Bài E

Mã nguồn Python:

1
2
x = int(input())
print(x ** 2 + 2 * x + 5)

Mã nguồn C++:

1
2
3
4
5
6
7
8
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a;
    cin >> a;
    cout << a * a + 2 * a + 5;
    return 0;
}

Bài F

Mã nguồn Python:

1
print(f'{(float(input()) - 32) / 9 * 5:.5f}')

Mã nguồn C++:

1
2
3
4
5
6
7
8
#include <bits/stdc++.h>
using namespace std;
int main(){
    double n;
    cin >> n;
    printf("%.5f\n", ((n - 32) * 5 / 9));
    return 0;
}

Bài G

Viết ngày 05/09/2024

Mã nguồn Python:

1
2
3
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
print(f"{((x1 - x2)**2 + (y1 - y2)**2)**0.5:.3f}")

Mã nguồn C++:

1
2
3
4
5
6
7
8
#include <bits/stdc++.h>
using namespace std;
int main(){
    int x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << fixed << setprecision(3) << sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
    return 0;
}

Bài H

Mã nguồn Python:

1
2
3
4
5
6
7
8
x = float(input())
if 0 <= x < 5:
    y = -x + 2.5
elif 5 <= x < 10:
    y = 2 - 1.5 * (x - 3) * (x - 3)
elif 10 <= x < 20:
    y = x / 2 - 1.5
print(f"{y:.3f}")

Mã nguồn C++:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include <bits/stdc++.h>
using namespace std;
int main(){
    double x, y;
    cin >> x;
    if (0 <= x && x < 5){
        y = -x + 2.5;
    }
    else if (5 <= x && x < 10){
        y = 2 - 1.5 * (x - 3) * (x - 3);
    }
    else if (10 <= x && x < 20){
        y = x / 2 - 1.5;
    }
    cout << fixed << setprecision(3) << y;
    return 0;
}

Bài I

Mã nguồn Python:

1
2
3
4
5
6
7
8
n = int(input())
def a():
    for i in range(2, n):
        if n % i == 0:
            print("No")
            return
    print("Yes")
a()

Mã nguồn C++:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    for (int i = 2; i <= n - 1; i++){
        if (n % i == 0){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}

Bài J

Mã nguồn Python:

1
2
3
4
5
w = int(input())
if w > 2 and w % 2 == 0:
    print("YES")
else:
    print("NO")

Mã nguồn C++:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#include <bits/stdc++.h>
using namespace std;
int main(){
    int w;
    cin >> w;
    if (w > 2 && w % 2 == 0){
        cout << "YES";
    }
    else{
        cout << "NO";
    }
    return 0;
}

Bài K

Mã nguồn Python:

1
2
3
4
5
6
7
n = int(input())
rt = 0
while n > 0:
    n -= 1
    if sum(map(int, input().split())) >= 2:
        rt += 1
print(rt)

Mã nguồn C++:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include <bits/stdc++.h>
using namespace std;
int main(){
    int lines, ret;
    ret = 0;
    cin >> lines;
    while (lines > 0){
        lines--;
        int x, y, z;
        cin >> x >> y >> z;
        if (x + y + z >= 2){
            ret++;
        }
    }
    cout << ret;
    return 0;
}

Bài L

Mã nguồn Python:

1
2
3
4
5
6
7
8
n = int(input())
while n > 0:
    n -= 1
    word = input()
    if len(word) > 10:
        print(word[0] + str(len(word) - 2) + word[-1])
    else:
        print(word)

Mã nguồn C++:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    while (n > 0){
        n--;
        string s;
        cin >> s;
        if (s.size() > 10){
            cout << s.substr(0, 1) << s.size() - 2 << s.substr(s.size() - 1, s.size()) << endl;
        }
        else{
            cout << s << endl;
        }
    }
    return 0;
}

Đề xuất đọc thêm

Ba kỹ năng cơ bản mà mọi lập trình viên mới cần phải nắm vững.


Hy vọng tài liệu này sẽ giúp ích cho quá trình học tập của bạn!

Built with Hugo
Theme Stack thiết kế bởi Jimmy