【DidaOJ】[1137]Thanksgiving KK Special - Accompanying a Junior Girl to Class

Problem Description

Loading...

Problem Analysis

This is the problem I remember most vividly from that year’s school contest — though to be honest, it wasn’t very well designed.

In fact, it turns into a pattern-finding problem: this is a simulation of one case of an odd-order magic square.

cpp
 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
#include<stdio.h>  
#include<string.h>  
  
int main() {  
    int t,N;  
    int i,j,k,m,n,mt,nt;  
    int a[200][200];  
    scanf("%d",&t);  
    while(t--){  
       memset(a,0,sizeof(a));  
       scanf("%d",&N);  
       for(i=1,n=1,m=N/2+1;i<=N*N;i++){  
       a[n][m]=i;  
       mt=m+1;nt=n-1;  
       if(mt>N)  
          mt=1;  
       if(nt<1)  
          nt=N;  
       if(a[nt][mt]!=0)  
          n=n+1;  
          else{  
             m=mt;  
             n=nt;  
       }  
    }  
       for(j=1;j<=N;j++){  
          for(k=1;k<=N;k++){  
             printf("%8d",a[j][k]);  
          }  
          printf("\n");  
       }  
    }  
    return 0;  
}

Problem link: Thanksgiving KK Special — Accompanying the Junior Girl to Class - Problem Details - Problems - DidaOJ

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...