Time limit per test
1 second
Memory limit per test
256 megabytes
Input
Standard Input
Output
Standard output
Gerald hasNYounger brothers and their number happens to be even. One day he boughtN2 candy
Bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integerKFrom 1N2 he
Has exactly one bagKCandies.
Help him giveNBags of candies to each brother so that all brothers got the same number of candies.
Input
The single line contains a single integerN(NIs
Even, 2 bytes ≤ averageNLimit ≤ limit 100)-the number of Gerald's brothers.
Output
Let's assume that Gerald indexes his brothers with numbers from 1N.
You need to printNLines, onI-Th
Line printNIntegers-the numbers of candies in the bags forI-Th
Brother. Naturally, all these numbers shoshould be distinct and be within limits from 1N2.
You can print the numbers in the lines in any order.
It is guaranteed that the solution exists at the given limits.
Sample test (s) Input
2
Output
1 42 3
Note
The sample shows Gerald's actions if he has two brothers. in this case, his bags contain 1, 2, 3 and 4 candies. he can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.
Description: This question is to select n pairs of numbers from 1 to n ^ 2 so that the sum of each pair of numbers is equal. The simplest thing is to pair the head and tail, and then move them in turn.
#include <cstdio>#include<iostream>using namespace std;int main(){int n,i;scanf("%d",&n);for(i=1;i<=(n*n)/2;i++){printf("%d %d\n",i,(n*n)-i+1);}return 0;}