fork download
  1. #define log(x) printf(#x": %d\n", x)
  2. a,b,c,d,e,i,j,x,y,**z;
  3. p(){
  4. j=y;
  5. while(j--){
  6. i=x;
  7. while(i--)printf("%3d ",z[x-i-1][y-j-1]);
  8. puts("");
  9. }
  10. }
  11. f(){
  12. if(c>0&&!d&&x-i-1==j){
  13. c=0;
  14. d=1;
  15. }
  16. else if(!c&&d>0&&x-i-1-y%2==y-j-1){
  17. c=-1;
  18. d=0;
  19. }
  20. else if(c<0&&!d&&i+!(y%2)-(x<y?!(x%2):0)==y-j-1){
  21. c=0;
  22. d=-1;
  23. }
  24. else if(!c&&d<0&&i-(x<y?!(x%2):0)==j){
  25. c=1;
  26. d=0;
  27. }
  28. printf("%d %d\n",c,d);
  29. i+=c;
  30. j+=d;
  31. }
  32. main(){
  33. scanf("%d%d",&x,&y);
  34. z=malloc(x*4);
  35. i=x;
  36. while(i--)z[i]=malloc(y*4);
  37.  
  38. if(x<y){
  39. a=x/2;
  40. b=y/2;
  41. a=a<b?a:b;
  42. b=(a<b?a:b)-!(x%2);
  43. d=1;
  44. }
  45. else{
  46. a=x/2-!(x%2);
  47. b=y/2-!(y%2);
  48. a=a<b?a:b;
  49. b=a<b?a:b;
  50. c=1;
  51. }
  52.  
  53. i=a;
  54. j=b;
  55.  
  56. while(e++<x*y){
  57. z[i][j]=e;
  58. printf("%d %d %d\n",e,i,j);
  59. f();
  60. }
  61.  
  62. p();
  63. }
Success #stdin #stdout 0s 1968KB
stdin
4 10
stdout
1 2 1
0 1
2 2 2
0 1
3 2 3
0 1
4 2 4
0 1
5 2 5
0 1
6 2 6
0 1
7 2 7
0 1
8 2 8
-1 0
9 1 8
0 -1
10 1 7
0 -1
11 1 6
0 -1
12 1 5
0 -1
13 1 4
0 -1
14 1 3
0 -1
15 1 2
0 -1
16 1 1
0 -1
17 1 0
1 0
18 2 0
1 0
19 3 0
0 1
20 3 1
0 1
21 3 2
0 1
22 3 3
0 1
23 3 4
0 1
24 3 5
0 1
25 3 6
0 1
26 3 7
0 1
27 3 8
0 1
28 3 9
-1 0
29 2 9
-1 0
30 1 9
-1 0
31 0 9
0 -1
32 0 8
0 -1
33 0 7
0 -1
34 0 6
0 -1
35 0 5
0 -1
36 0 4
0 -1
37 0 3
0 -1
38 0 2
0 -1
39 0 1
0 -1
40 0 0
0 -1
 40  17  18  19 
 39  16   1  20 
 38  15   2  21 
 37  14   3  22 
 36  13   4  23 
 35  12   5  24 
 34  11   6  25 
 33  10   7  26 
 32   9   8  27 
 31  30  29  28