문제 자주 못풀어서 미안; -_-a
#include#include int main() { int n; int cards; int *linear; int i, j; int ind; scanf( "%d", &n ); while( n > 0 ) { scanf( "%d", &cards ); linear = (int *) calloc( cards, sizeof(int) ); ind = 0; for( i = 1; i <= cards; i++ ) { j = 0; while( linear[ind] != 0 ) { ind = (ind + 1) % cards; } while(1) { if( linear[ind] == 0 ) { ind = (ind + 1) % cards; j++; if( j == i ) { while( linear[ind] != 0 ) { ind = (ind + 1) % cards; } linear[ind] = i; break; } } else { ind = (ind + 1) % cards; } } } for( i = 0; i < cards; i++ ) { printf( "%d%c", linear[i], (i == cards-1)? '\n': ' ' ); } free( linear ); n--; } return 0; }
'Solutions > Mr.K's Solution' 카테고리의 다른 글
PKU 2181. Jumping Cows. [판정:AC] (3) | 2011.03.16 |
---|---|
PKU 2291. Rotten Ropes. [판정:AC] (0) | 2011.03.11 |
PKU 3085. Quick Change. [판정:AC] (0) | 2010.10.07 |
PKU 2260. Error Correction. [판정:AC] (0) | 2010.09.07 |
UVa 341. Non-Stop Travel. [판정:TLE] (1) | 2010.08.29 |