raynstard #3556(2007/10/29 13:26 GMT) [ C ] Rating0/0=0.00
水の量を均一にすればよいのだから最小公倍数とか使えそうなんだけど バカにはよくわからないので一つ一つでカウントしていった。 一番多いところ-二番目に多いところの差を 半分ずつわければもうちょっと計算減らせそうだけど。。。 4L,2L,10L ではBがのこって 10回?
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
#include <stdio.h> #include <stdint.h> #define BAKET_SWAP(a,b) { uint32_t *work = *(a); *(a) = *(b); *(b) = work; } void baket_sort( uint32_t **baket[] ) { int is_changed = 1; while( is_changed == 1 ) { is_changed = 0; if( (*(baket[0])) < (*(baket[2])) ){ BAKET_SWAP(baket[0], baket[2]); is_changed = 1;} if( (*(baket[0])) < (*(baket[1])) ){ BAKET_SWAP(baket[0], baket[1]); is_changed = 1;} if( (*(baket[1])) < (*(baket[2])) ){ BAKET_SWAP(baket[1], baket[2]); is_changed = 1;} } } uint64_t play_game(uint32_t A, uint32_t B, uint32_t C) { uint32_t *baket[] = {&A, &B, &C}; uint64_t count = 0; while( 1 ) { /* 水の量が均一になれば終わり */ if( A == B ) { printf("のこるのは C\n"); count += A; break; } if( A == C ) { printf("のこるのは B\n"); count += A; break; } if( B == C ) { printf("のこるのは B\n"); count += B; break; } /* 昇順にバブルソート */ baket_sort( &baket ); (*(baket[0])) --; (*(baket[1])) --; (*(baket[2])) += 2; count ++; } return count; } int main(int argc, char *argv[]) { printf("ans = %lld\n", play_game(4,2,10)); printf("ans = %lld\n", play_game(3,1,12)); return 0; }
Rating0/0=0.00-0+
1 reply [ reply ]
raynstard
#3556()
[
C
]
Rating0/0=0.00
Rating0/0=0.00-0+
1 reply [ reply ]