cses

cses solutions in pure c
git clone git://git.superpozycja.net/cses
log | files | refs

s.c (537B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 #include <string.h>
      4 #include <stdint.h>
      5 
      6 int solve()
      7 {
      8 	int *row, *col;
      9 	int i, j, x;
     10 	int n, m;
     11 
     12 	scanf("%d", &n);
     13 
     14 	m = 2 * n;
     15 
     16 	row = malloc(sizeof(int) * m * n);
     17 	col = malloc(sizeof(int) * m * n);
     18 
     19 	for (i = 0; i < n; i++) {
     20 		for (j = 0; j < n; j++){
     21 			for (x = 0; x < m; x++)
     22 				if (!(row[m * i + x] || col[m * j + x]))
     23 					break;
     24 
     25 			row[m * i + x] = 1;
     26 			col[m * j + x] = 1;
     27 			printf("%d ", x);
     28 		}
     29 		printf("\n");
     30 	}
     31 
     32 	return 0;
     33 }
     34 
     35 int main()
     36 {
     37 	int t = 1;
     38 	while (t--)
     39 		solve();
     40 }