CodeForces #194 Div.2 A. Candy Bags

输入2时:

输出:(每行的和为 5 )

1  4

2  3

 

输入4时:

输出:(每行的和为 34 )

1  16  2  15

3  14  4  13

5  12  6  11

7  10  8  9

 

输入6时:

输出:(每行的和为 101 )

1  36  2  35  3  34

4  33  5  32  6  31

7  30  8  29  9  28

10  27  11  26  12  25

13  24  14  23  15  22

16  21  17  20  18  19

 

相信你已经看出规律来了



AC代码:

#include<stdio.h>

using namespace std;

int main() {

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    int n;
    while(scanf("%d",&n)!=EOF) {
        for(int i=0; i<n; i++) {
            for(int j=1; j<=n/2; j++)
                printf("%d %d ", i*(n/2)+j, n*n-(i*(n/2)+j)+1 );
            printf("\n");
        }
    }
    return 0;
}




你可能感兴趣的:(CodeForces #194 Div.2 A. Candy Bags)