05-树7 堆中的路径 (25分)

ac代码

#include

#define MaxN 1001
#define MinH -10001

int H[MaxN],size;

void Create()
{
    size = 0;
    H[0] = MinH;
}

void Insert(int X)
{
    int i;
    for(i=++size;H[i/2]>X;i/=2)
        H[i] = H[i/2];
    H[i] = X;   
}

int main()
{
    int N,M,x;
    scanf("%d %d",&N,&M);
    Create();
    for(int i=0;i"%d",&x);
        Insert(x);
    }
    int j;
    for(int i=0;i"%d",&j);
        printf("%d",H[j]);
        while(j>1){
            j /= 2;
            printf(" %d",H[j]);
        } 
        printf("\n");
    }

    return 0;
}
















你可能感兴趣的:(PAT(A))