Tích
ok
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll m,n,t=1;
cin>>m>>n;
for (int i=m;i<=n;i++)
t*=i;
cout<<t;
return 0;
}
Luỹ thừa
C++:
#include <iostream>
using namespace std;
__int128 power(__int128 a, __int128 b) {
__int128 result = 1;
while (b) {
if (b % 2) result *= a;
a *= a;
b /= 2;
}
return result;
}
void print(__int128 x) {
if (x == 0) {
cout << 0;
return;
}
string res;
while (x > 0) {
res = char('0' + x % 10) + res;
x /= 10;
}
cout << res;
}
int main() {
unsigned long long a, b;
cin >> a >> b;
print(power(a, b));
return 0;
}
Tính toán
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
double a, b, res;
char op;
cin >> a >> b >> op;
switch (op)
{
case '+': res = a + b;
break;
case '-': res = a - b;
break;
case '*': res = a * b;
break;
case '/': res = a / b;
break;
}
double epsilon = 1e-9;
res = round((res + epsilon) * 100.0) / 100.0;
cout << fixed << setprecision(2) << res << endl;
return 0;
}
code cho ae chưa lm đc
Kiểm tra tam giác #1
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll a,b,c;
cin>>a>>b>>c;
if (a<b+c&&b<c+a&&c<a+b)
cout<<"YES";
else cout<<"NO";
return 0;
}
Tích lớn nhất
#include <iostream>
using namespace std;
int main() {
long long n;
cin >> n;
long long a = n / 2;
long long b = n - a;
cout << a << " " << b << endl;
return 0;
}
Two pointer 1B
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
j = 0
for bi in b:
while j < n and a[j] < bi:
j += 1
c.append(j)
print(' '.join(map(str, c)))
Hướng dẫn cho {0}Luyện tập
Người đưa hướng dẫn ơi, bạn có thể đưa hướng dẫn kĩ hơn cho mình dễ hiểu được không?
Mình dùng Python, không phải C++.
Chuyển đổi xâu
Ủa sao sai vậy, mình kiểm tra các test case thử trong Thonny thấy đúng mà sao nó chấm sai (mới kiểm tra test case #2), mà có 20 điểm??
Code Python 3
s = input()
res = ''; count = 0
for a in range (0, len (s)):
if s [a] == ' ':
count = 0
else:
count += 1
if count == 1:
t = s [a].upper()
else:
t = s [a].lower()
res += t
print (res.strip())
Tổng kết
Ý tưởng ở đây kiểm tra có phải là dấu cách rồi in hoa nó
Có ai có cách khác mà cũng AC không
Hoán vị [APERM] (HSG 11 Chuyên Vĩnh Phúc 2023-2024)
include <bits/stdc++.h>
using namespace std;
long long n,i,k,j,x,d,rs=0,start,y,z,t,chan,le,l,r,m,lnow,rnow,cr,top;
// map<long long, long long> f;
// priority_queue< long long, vector<long long>, greater<long long> >khunganh;
// bool sx(pair<long long, long long> x, pair<long long, long long> y)
// {
// if(x.first==y.first) return x.second<y.second;
// return x.first\<y.first;
// }
priority_queue\<long long, vector\<long long>, greater\<long long> >so;
long long f[1000006][4],f1[1000006];
string s;
long long a[1000006],a1,a2,a3;
map\<long long, long long> mp;
int main()
{
freopen("test.inp","r",stdin);
freopen("test.out","w",stdout);
cin>>n>>k;
top=1e18;
for(i=1;i<=n;i++) cin>>a[i];
for(i=1;i<=k;i++)
{
so.push(a[i]);
}
top=so.top();
cout<<top<<'\n';
for(i=k+1;i<=n;i++)
{
if(a[i]<top) cout<<top<<'\n';
else
{
so.push(a[i]);
so.pop();
top=so.top();
cout<<top<<'\n';
}
}
}
Hoán vị [APERM] (HSG 11 Chuyên Vĩnh Phúc 2023-2024)
Tóm tắt cho ai bí ý tưởng:
- Tạo một priority_queue min chứa các số lớn thứ 1 -> k;
- Đặt biến top là số lớn thứ k
- Duyệt từ i=k+1 -> i=n: Nếu A[i]<top thì top không thay đổi, nếu A[i]>top thì cho A[i] vào priority_queue rồi loại bỏ giá trị nhỏ nhất (so.pop() nghĩa là loại bỏ số lớn thứ k+1) thì lúc này top = so.top() ( là số lớn thứ k )