Đăng nhập để hỏi chi tiết


Hãy luôn nhớ cảm ơn và vote 5*
nếu câu trả lời hữu ích nhé!
// author: cody
#include <bits/stdc++.h>
using namespace std;
long long a[100000];
void sort(int l, int r) {
int i = l;
int j = r;
long long x = a[(l + r) / 2];
do {
while (a[i] < x)
i++;
while (x < a[j])
j--;
if (!(i > j)) {
swap(a[i], a[j]);
i++;
j--;
}
} while (i <= j);
if (l < j)
sort(l, j);
if (i < r)
sort(i, r);
}
int main() {
freopen("findnewpos.inp" , "r", stdin);
freopen("findnewpos.out" , "w", stdout);
long long n, k, t, d = 0;
cin >> n >> k;
for (int i = 1; i <= n; i++)
cin >> a[i];
t = a[k];
for (int i = 1; i <= n; i++) {
if (a[i] == t && i == k)
break;
else if (a[i] == t && i < k)
d++;
}
sort(1, n);
for (int i = 1; i <= n; i++) {
if (a[i] == t) {
cout << i + d;
return 0;
}
}
return 0;
}
Hãy giúp mọi người biết câu trả lời này thế nào?

/*
#khanhtaon(*^▽^*)
*/
#include <bits/stdc++.h>
using namespace std;
int n, vt, h, d;
vector <long long> ma;
int main()
{
freopen("findnewpos.inp" , "r", stdin);
freopen("findnewpos.out" , "w", stdout);
cin >> n >> vt;
ma.resize(n);
for(int a = 0; a < n; a++)
cin >> ma[a];
h = ma[vt-1];
for(int a = 0; a < n; a++)
if(ma[a] == h && a <= vt-1) d++;
sort(ma.begin(), ma.end());
for(int a = 0; a < n; a++)
if(ma[a] == h)
{
cout << a+d;
exit(0);
}
return 0;
}
Hãy giúp mọi người biết câu trả lời này thế nào?

Bảng tin
5
190
5
thanks ban
5
190
5
mik full r
725
9733
337
um