7-38 寻找大富翁 (25分)--排序
标签:bsp else 超时 stream for pac class long namespace
多提交几次就不超时了(#滑稽)
1 #include 2 using namespace std;
3 long int a[1000005];
4 long int N;
5 inline void swap(long int* a, long int* b)
6 {
7 int temp = *a;
8 *a = *b;
9 *b = temp;
10 }
11 inline void percdown(long int a[], long int r, long int N)
12 {
13 long int child;
14 long int temp;
15
16 temp = a[r];
17 for (; 2 * r + 1 child)
18 {
19 child = 2 * r + 1;
20 if (2 * r + 2 2 * r + 2] 2 * r + 1])
21 child++;
22 if (a[child] 24 a[r] = a[child];
25 }
26 else
27 break;
28 }
29 a[r] = temp;
30 }
31
32 void Heap_Sort(long int a[])
33 {
34
35 for (long int i = N / 2; i >= 0; i--)
36 {
37 percdown(a, i, N);
38 }
39
40 for (long int i = N - 1; i > 0; i--) 42 swap(&a[0], &a[i]);
43 percdown(a, 0, i);
44 }
45 }
46 int main()
47 {
48 long int M;
49 cin >> N >> M;
50 if(NN;
51 for (long int i = 0; i )
52 {
53 cin >> a[i];
54 }
55 Heap_Sort(a);
56 for (long int i = 0; i )
57 {
58 printf("%ld",a[i]);
59 if (i != M - 1)printf(" ");
60 }
61 return 0;
62 }
7-38 寻找大富翁 (25分)--排序
标签:bsp else 超时 stream for pac class long namespace
原文地址:https://www.cnblogs.com/2020R/p/12770984.html
评论