Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct node {
  6.     long long v;
  7.     int h;
  8.     node *l;
  9.     node *r;
  10. };
  11. long long a=0,b=0;
  12.  
  13. int h(node *n){
  14.     if (n==NULL){
  15.         return 1;
  16.     }else{
  17.         a+=h(n->l);
  18.         b+=h(n->r);
  19.     }
  20. }
  21.  
  22. void pridaj(long long x, node *n, int _h) {
  23.     if (n == NULL) {
  24.         n = new node;
  25.         n->l = NULL;
  26.         n->r = NULL;
  27.         n->v = x;
  28.         n->h = _h;
  29.         return;
  30.     }
  31.     if (x == n->v){
  32.         return;
  33.     }
  34.     if (x > n->v) {
  35.         if (n->r == NULL){
  36.             n->r = new node;
  37.             n->r->l = NULL;
  38.             n->r->r = NULL;
  39.             n->r->v = x;
  40.             n->r->h = _h;
  41.             return;
  42.         }else{
  43.         pridaj(x, n.r, h+1);
  44.         }
  45.     }
  46.     if (x < n->v) {
  47.         if (n->l == NULL){
  48.             n->l = new node;
  49.             n->l->l = NULL;
  50.             n->l->r = NULL;
  51.             n->l->v = x;
  52.             n->l->h = _h;
  53.             return;
  54.         }else{
  55.             pridaj(x,n.l, h+1);
  56.         }
  57.  
  58.     }
  59. }
  60.  
  61. int main(int argc, char** argv) {
  62.     node *root=new node();
  63.     root->l = NULL;
  64.     root->r = NULL;
  65.     root->h = 0;
  66.     int t;
  67.     cin >> t;
  68.     for (int i = 0; i<t; i++){
  69.         int n, x;
  70.         cin>>n>>x;
  71.         int tmp=(x * 25173 + 13849) % 65536;
  72.         root->v=tmp;
  73.         for (int j=1; j<n; j++){
  74.             tmp=(tmp * 25173 + 13849) % 65536;
  75.             pridaj(tmp, root, root->h);
  76.         }
  77.     }
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement