#include<cstdio>
#include<cmath>
#include<iostream>
#include "cielib.h"
using namespace std;
int* dodaj(int tab[], int poz, int move, int r) {
tab[poz] += move;
if (tab[poz] >= r) tab[poz] = r;
if (tab[poz] < 0) tab[poz] = 0;
return tab;
}
int main(){
int d = podajD(); // liczba wymiarów
int k = podajK();
int r = podajR(); // długość lasu
int current[d];
int av = (int) (r)/2; int move = (int)(r+1)/2;
for (int i = 0; i < d; i++) current[i] = av;
int cie = czyCieplo(current);
while (true) { // break na końcu move == 1
for (int i = 0; i <d ;i ++) {
int start = current[i], next, l;
int res = czyCieplo(dodaj(current, i, move, r));
next = current[i];
current[i] = start;
if (res == 0) {
res = -czyCieplo(current);
}
int res2 = czyCieplo(dodaj(current, i, -move, r));
l = current[i];
current[i] = start;
if (res2 == 0) {
res2 = -czyCieplo(current);
}
if (res > res2) {
// cout << "do przodu \n";
current[i] = (start+next+1)/2;
} else if (res < res2) {
// cout << " do tyłu \n";
current[i] = (start + l)/2;
} else {
// cout << "bez zmian \n";
}
czyCieplo(current);
}
if (move == 1) break;
move = (move+1)/2;
}
znalazlem(current);
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | #include<cstdio> #include<cmath> #include<iostream> #include "cielib.h" using namespace std; int* dodaj(int tab[], int poz, int move, int r) { tab[poz] += move; if (tab[poz] >= r) tab[poz] = r; if (tab[poz] < 0) tab[poz] = 0; return tab; } int main(){ int d = podajD(); // liczba wymiarów int k = podajK(); int r = podajR(); // długość lasu int current[d]; int av = (int) (r)/2; int move = (int)(r+1)/2; for (int i = 0; i < d; i++) current[i] = av; int cie = czyCieplo(current); while (true) { // break na końcu move == 1 for (int i = 0; i <d ;i ++) { int start = current[i], next, l; int res = czyCieplo(dodaj(current, i, move, r)); next = current[i]; current[i] = start; if (res == 0) { res = -czyCieplo(current); } int res2 = czyCieplo(dodaj(current, i, -move, r)); l = current[i]; current[i] = start; if (res2 == 0) { res2 = -czyCieplo(current); } if (res > res2) { // cout << "do przodu \n"; current[i] = (start+next+1)/2; } else if (res < res2) { // cout << " do tyłu \n"; current[i] = (start + l)/2; } else { // cout << "bez zmian \n"; } czyCieplo(current); } if (move == 1) break; move = (move+1)/2; } znalazlem(current); return 0; } |
English