#include "cielib.h" int main(void) { int d = podajD(); int r = podajR(); int* positionArray = new int [ d ]; int* partitionMinPoints = new int [ d ]; int* partitionMaxPoints = new int [ d ]; short* ps_helperArray = new short [ d ]; int tmp; for ( int i = 0; i < d; ++i ) { partitionMinPoints[ i ] = 0; partitionMaxPoints[ i ] = r; positionArray[ i ] = r / 2; } bool b_endflag = false; while ( !b_endflag ) { b_endflag = true; for ( int i = 0; i < d; ++i ) { if ( partitionMinPoints[ i ] != partitionMaxPoints[ i ] ) { tmp = positionArray[ i ]; positionArray[ i ] = partitionMinPoints[ i ]; czyCieplo( positionArray ); positionArray[ i ] = partitionMaxPoints[ i ]; ps_helperArray[ i ] = czyCieplo( positionArray ); if ( ! ps_helperArray[ i ] && ( ( partitionMaxPoints[ i ] - partitionMinPoints[ i ] ) % 2 ) ) //odd numbers { if ( partitionMaxPoints[ i ] - partitionMinPoints[ i ] > 1 ) { positionArray[ i ] = partitionMinPoints[ i ] + 1; if ( !czyCieplo( positionArray ) ) ps_helperArray[ i ] = 1; else { positionArray[ i ] = partitionMaxPoints[ i ] - 1; ps_helperArray[ i ] = czyCieplo( positionArray ); } } else // last one { if ( partitionMinPoints[ i ] > 0 ) { positionArray[ i ] = partitionMinPoints[ i ] - 1; czyCieplo( positionArray ); positionArray[ i ] = partitionMaxPoints[ i ]; ps_helperArray[ i ] = czyCieplo( positionArray ); } else { positionArray[ i ] = partitionMaxPoints[ i ] + 1; czyCieplo( positionArray ); positionArray[ i ] = partitionMinPoints[ i ]; ps_helperArray[ i ] = czyCieplo( positionArray ) ? 0 : 1; } } } positionArray[ i ] = tmp; } } int couter = 0; for ( int i = 0; i < d; ++i ) { if ( partitionMaxPoints[ i ] != partitionMinPoints[ i ] ) { if ( ps_helperArray[ i ] ) partitionMinPoints[ i ] = positionArray[ i ] + 1; else partitionMaxPoints[ i ] = positionArray[ i ]; positionArray[ i ] = partitionMinPoints[ i ] + ( ( partitionMaxPoints[ i ] - partitionMinPoints[ i ] ) /2 ); b_endflag = false; } } } znalazlem( partitionMinPoints ); delete positionArray; delete partitionMinPoints; delete partitionMaxPoints; delete ps_helperArray; 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | #include "cielib.h" int main(void) { int d = podajD(); int r = podajR(); int* positionArray = new int [ d ]; int* partitionMinPoints = new int [ d ]; int* partitionMaxPoints = new int [ d ]; short* ps_helperArray = new short [ d ]; int tmp; for ( int i = 0; i < d; ++i ) { partitionMinPoints[ i ] = 0; partitionMaxPoints[ i ] = r; positionArray[ i ] = r / 2; } bool b_endflag = false; while ( !b_endflag ) { b_endflag = true; for ( int i = 0; i < d; ++i ) { if ( partitionMinPoints[ i ] != partitionMaxPoints[ i ] ) { tmp = positionArray[ i ]; positionArray[ i ] = partitionMinPoints[ i ]; czyCieplo( positionArray ); positionArray[ i ] = partitionMaxPoints[ i ]; ps_helperArray[ i ] = czyCieplo( positionArray ); if ( ! ps_helperArray[ i ] && ( ( partitionMaxPoints[ i ] - partitionMinPoints[ i ] ) % 2 ) ) //odd numbers { if ( partitionMaxPoints[ i ] - partitionMinPoints[ i ] > 1 ) { positionArray[ i ] = partitionMinPoints[ i ] + 1; if ( !czyCieplo( positionArray ) ) ps_helperArray[ i ] = 1; else { positionArray[ i ] = partitionMaxPoints[ i ] - 1; ps_helperArray[ i ] = czyCieplo( positionArray ); } } else // last one { if ( partitionMinPoints[ i ] > 0 ) { positionArray[ i ] = partitionMinPoints[ i ] - 1; czyCieplo( positionArray ); positionArray[ i ] = partitionMaxPoints[ i ]; ps_helperArray[ i ] = czyCieplo( positionArray ); } else { positionArray[ i ] = partitionMaxPoints[ i ] + 1; czyCieplo( positionArray ); positionArray[ i ] = partitionMinPoints[ i ]; ps_helperArray[ i ] = czyCieplo( positionArray ) ? 0 : 1; } } } positionArray[ i ] = tmp; } } int couter = 0; for ( int i = 0; i < d; ++i ) { if ( partitionMaxPoints[ i ] != partitionMinPoints[ i ] ) { if ( ps_helperArray[ i ] ) partitionMinPoints[ i ] = positionArray[ i ] + 1; else partitionMaxPoints[ i ] = positionArray[ i ]; positionArray[ i ] = partitionMinPoints[ i ] + ( ( partitionMaxPoints[ i ] - partitionMinPoints[ i ] ) /2 ); b_endflag = false; } } } znalazlem( partitionMinPoints ); delete positionArray; delete partitionMinPoints; delete partitionMaxPoints; delete ps_helperArray; return 0; }; |