Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef CIELIB_C
- #define CIELIB_C
- #include <stdio.h>
- #include <random>
- #include <stdlib.h>
- #include<iostream>
- int d_v, k_v, r_v;
- void init(void);
- int podajD(void) {
- init();
- return d_v;
- }
- int podajK(void) {
- init();
- return k_v;
- }
- int podajR(void) {
- init();
- return r_v;
- }
- int pos[500];
- void init(void) {
- static int initialized = -1;
- if(initialized != -1) {
- return;
- }
- initialized = 1;
- /*d_v=10;
- k_v=10000;
- r_v=1024;*/
- d_v=500;
- k_v=100*d_v;
- r_v=2;
- std::random_device rd;
- std::mt19937 gen{rd()};
- std::uniform_int_distribution<int>dist(0,r_v);
- // printf("Podaj pozycje Krotki:\n");
- for(int i = 0; i < podajD(); ++i) {
- pos[i] = dist(gen);
- }
- /*
- pos[2]=0;
- pos[11]=0;
- pos[1]=0;
- pos[80]=0;
- pos[10]=0;
- pos[100]=r_v;
- pos[61]=r_v;
- pos[31]=r_v;
- pos[14]=r_v;
- pos[71]=r_v;
- */
- //pos[0]=1;
- //pos[1]= 3;
- }
- void init2(void) {
- static int initialized = -1;
- if(initialized != -1) {
- return;
- }
- initialized = 1;
- printf("Podaj d: ");
- scanf("%d", &d_v);
- printf("Podaj k: ");
- scanf("%d", &k_v);
- printf("Podaj r: ");
- scanf("%d", &r_v);
- printf("Podaj pozycje Krotki:\n");
- for(int i = 0; i < podajD(); ++i) {
- scanf("%d", &pos[i]);
- }
- }
- int call = 0;
- int czyCieplo(int answer[]) {
- init();
- call += 1;
- if(call > podajK()) {
- printf("Przekroczono limit k = %d.", k_v);
- exit(1);
- }
- static int ldiff = -1;
- int diff = 0;
- for(int d, i = 0; i < podajD(); ++i) {
- if ((answer[i]<0) || (answer[i]>r_v)){
- std::cout<<"DUPADUPADUPADUPADUPADUPADUzakresUAPDAUDPADUPADUA"<<std::endl;
- }
- d = pos[i] - answer[i];
- d = (d<0) ? -d : d;
- diff = (d > diff) ? d : diff;
- }
- const int result = (diff < ldiff) ? 1 : 0;
- ldiff = diff;
- return result;
- }
- void znalazlem(int answer[]) {
- init();
- printf("Podano:\n");
- for(int i = 0; i < podajD(); ++i) {
- printf("%d%c", pos[i], (i + 1 == podajD()) ? '\n' : ' ');
- }
- int k = 1;
- for(int i = 0; i < podajD(); ++i) {
- if(answer[i] != pos[i]) {
- printf("NIE %d na %d!\n", answer[i], i);
- k = -1;
- }
- }
- if(k == 1) {
- printf("OK --- %d zapytan\n%0.3f zapytan na wymiar/n", call, call/(float)d_v);
- }
- exit(0);
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement