被几道30分的题困扰好久 = = 果然自己还是太弱了
这道25分的还是比较简单
做做就做出来了
#include <iostream> #include <cstring> using namespace std; long long i; long long *A; void insert(long long a); int main() { long long n, m; cin >> n >> m; A = (long long *)malloc((n + 1)*sizeof(long long)); for (i = 1; i <= n; i++){ long long a; cin >> a; insert(a); } for (i = 0; i < m; i++){ long long q; cin >> q; cout << A[q]; q /= 2; while (q>0){ cout << " " << A[q]; q /= 2; } cout << endl; } } void insert(long long a) { long long m = i; A[m] = a; while ( m/2 > 0){ //循环条件一开始写成了m>0,对计算机来说 = = 真是不一样啊 if (A[m] < A[m / 2]){ A[m] ^= A[m / 2]; A[m / 2] ^= A[m]; A[m] ^= A[m / 2]; } m /= 2; } }
时间: 2024-12-24 15:00:24