vakho

ALG Problem N1

Nov 1st, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int n, a[3030];
  7. int t[6060];
  8.  
  9. void add(int i, int v) {
  10.     if (t[i] == -1) {
  11.         t[i] = v;
  12.         return;
  13.     }
  14.     if (v < t[i])
  15.         add(i*2, v);
  16.     else
  17.         add(i*2+1, v);
  18. }
  19.  
  20. void dfs(int i) {
  21.     if (t[i] == -1)
  22.         return;
  23.     dfs(i*2+1);
  24.     dfs(i*2);
  25.     printf("%i", t[i]);
  26. }
  27.  
  28. int main()
  29. {
  30.     scanf("%i", &n);
  31.     for (int i = 0; i < n; i++)
  32.         scanf("%i", &a[i]);
  33.     for (int i = 0; i < 20*n; i++) // araoptimaluria
  34.         t[i] = -1;
  35.     for (int i = n-1; i >= 0; i--)
  36.         add(1, a[i]);
  37.     dfs(1);
  38.     system("PAUSE");
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment