Advertisement
bartekltg

rand_cei_lib

Nov 25th, 2016
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. #ifndef CIELIB_C
  2. #define CIELIB_C
  3.  
  4. #include <stdio.h>
  5. #include <random>
  6. #include <stdlib.h>
  7. #include<iostream>
  8.  
  9. int d_v, k_v, r_v;
  10.  
  11. void init(void);
  12.  
  13. int podajD(void) {
  14.     init();
  15.  
  16.     return d_v;
  17. }
  18.  
  19. int podajK(void) {
  20.     init();
  21.  
  22.     return k_v;
  23. }
  24.  
  25. int podajR(void) {
  26.     init();
  27.  
  28.     return r_v;
  29. }
  30.  
  31. int pos[500];
  32.  
  33.  
  34. void init(void) {
  35.     static int initialized = -1;
  36.     if(initialized != -1) {
  37.         return;
  38.     }
  39.     initialized = 1;
  40.  
  41.  
  42.     /*d_v=10;
  43.     k_v=10000;
  44.     r_v=1024;*/
  45.     d_v=500;
  46.     k_v=100*d_v;
  47.     r_v=2;
  48.  
  49.     std::random_device rd;
  50.     std::mt19937 gen{rd()};
  51.     std::uniform_int_distribution<int>dist(0,r_v);
  52.  
  53.    // printf("Podaj pozycje Krotki:\n");
  54.     for(int i = 0; i < podajD(); ++i) {
  55.         pos[i] = dist(gen);
  56.     }
  57. /*
  58.     pos[2]=0;
  59.     pos[11]=0;
  60.     pos[1]=0;
  61.     pos[80]=0;
  62.     pos[10]=0;
  63.     pos[100]=r_v;
  64.     pos[61]=r_v;
  65.     pos[31]=r_v;
  66.     pos[14]=r_v;
  67.     pos[71]=r_v;
  68. */
  69.     //pos[0]=1;
  70.     //pos[1]= 3;
  71.  
  72. }
  73.  
  74. void init2(void) {
  75.     static int initialized = -1;
  76.     if(initialized != -1) {
  77.         return;
  78.     }
  79.     initialized = 1;
  80.  
  81.     printf("Podaj d: ");
  82.     scanf("%d", &d_v);
  83.     printf("Podaj k: ");
  84.     scanf("%d", &k_v);
  85.     printf("Podaj r: ");
  86.     scanf("%d", &r_v);
  87.  
  88.     printf("Podaj pozycje Krotki:\n");
  89.     for(int i = 0; i < podajD(); ++i) {
  90.         scanf("%d", &pos[i]);
  91.     }
  92. }
  93.  
  94. int call = 0;
  95.  
  96. int czyCieplo(int answer[]) {
  97.     init();
  98.  
  99.     call += 1;
  100.     if(call > podajK()) {
  101.         printf("Przekroczono limit k = %d.", k_v);
  102.         exit(1);
  103.     }
  104.  
  105.     static int ldiff = -1;
  106.     int diff = 0;
  107.  
  108.     for(int d, i = 0; i < podajD(); ++i) {
  109.         if ((answer[i]<0) || (answer[i]>r_v)){
  110.             std::cout<<"DUPADUPADUPADUPADUPADUPADUzakresUAPDAUDPADUPADUA"<<std::endl;
  111.         }
  112.  
  113.         d = pos[i] - answer[i];
  114.         d = (d<0) ? -d : d;
  115.  
  116.         diff = (d > diff) ? d : diff;
  117.     }
  118.  
  119.     const int result = (diff < ldiff) ? 1 : 0;
  120.     ldiff = diff;
  121.  
  122.     return result;
  123. }
  124.  
  125. void znalazlem(int answer[]) {
  126.     init();
  127.  
  128.     printf("Podano:\n");
  129.     for(int i = 0; i < podajD(); ++i) {
  130.         printf("%d%c", pos[i], (i + 1 == podajD()) ? '\n' : ' ');
  131.     }
  132.  
  133.     int k = 1;
  134.     for(int i = 0; i < podajD(); ++i) {
  135.         if(answer[i] != pos[i]) {
  136.             printf("NIE %d na %d!\n", answer[i], i);
  137.             k = -1;
  138.         }
  139.     }
  140.  
  141.     if(k == 1) {
  142.         printf("OK --- %d zapytan\n%0.3f zapytan na wymiar/n", call, call/(float)d_v);
  143.     }
  144.  
  145.     exit(0);
  146. }
  147.  
  148. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement