A. Candy Bags
 
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Gerald has n younger brothers and their number happens to be even. One day he bought n2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n2 he has exactly one bag with kcandies.

Help him give n bags of candies to each brother so that all brothers got the same number of candies.

Input

The single line contains a single integer n (n is even, 2 ≤ n ≤ 100) — the number of Gerald's brothers.

Output

Let's assume that Gerald indexes his brothers with numbers from 1 to n. You need to print n lines, on the i-th line print n integers — the numbers of candies in the bags for the i-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to n2. 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 4
2 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.

输入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

相信你已经看出规律来了,代码如下:

#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; int main() { //freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout); int n;
while(~scanf("%d",&n)){
for(int i=;i<n;i++){
for(int j=;j<=n/;j++)
printf("%d %d ",i*(n/)+j,n*n-(i*(n/)+j)+);
printf("\n");
}
}
return ;
}

A. Candy Bags的更多相关文章

  1. Candy Bags

    读懂了题就会发现这是个超级大水题 Description Gerald has n younger brothers and their number happens to be even. One ...

  2. F - Candy Bags

    A. Candy Bags time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  3. 334A Candy Bags

    A. Candy Bags time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. codeforces A. Candy Bags 解题报告

    题目链接:http://codeforces.com/contest/334/problem/A 题意:有n个人,将1-n袋(第 i  袋共有 i  颗糖果,1<= i  <=n)所有的糖 ...

  5. codeforces 334A - Candy Bags

    忘了是偶数了,在纸上画奇数画了半天... #include<cstdio> #include<cstring> #include<cstdlib> #include ...

  6. Candy Distribution

    Kids like candies, so much that they start beating each other if the candies are not fairly distribu ...

  7. CodeForces Round 194 Div2

    A. Candy Bagstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputs ...

  8. Codeforces Round #194 (Div.1 + Div. 2)

    A. Candy Bags 总糖果数\(\frac{n^2(n^2+1)}{2}\),所以每人的数量为\(\frac{n}{2}(n^2+1)\) \(n\)是偶数. B. Eight Point S ...

  9. [LeetCode] Candy 分糖果问题

    There are N children standing in a line. Each child is assigned a rating value. You are giving candi ...

随机推荐

  1. JPA(二):HellWord工程

    使用JPA持久化对象的操作步骤: 1)创建persistence.xml,在这个文件中配置持久化单元: --- 需要指定跟哪个数据库进行交互: --- 需要指定JPA使用哪个持久化的框架以及配置该框架 ...

  2. c/c++ sizeof运算符详解以及对象大小

    原文:http://krystism.is-programmer.com/posts/41468.html 学过c的都知道sizeof运算符.不过还是需要注意以下几点.先从c的sizeof说起: 1. ...

  3. 'Newtonsoft.Json' already has a dependency defined for 'NETStandard.Library'

    安装NEST的时候报了如下的错误: PM> Install-Package NEST Attempting to resolve dependency 'Elasticsearch.Net (≥ ...

  4. 清空npm缓存

    nodejs 清空 npm 缓存 npm cache clean -f

  5. IDEA 禁止自动导入引用包 取消import包

    http://www.oschina.net/question/2010061_226765 我想拷贝一小段代码,或者我就是不想引入拷贝来的包,我该怎么取消掉idea的自动导入import包呢? 找到 ...

  6. 推荐一些socket工具,TCP、UDP调试、抓包工具

    还记得我在很久很久以前和大家推荐的Fiddler和Charles debugger么?他们都是HTTP的神器级调试工具,非常非常的好用.好工具能让你事半功倍,基本上,我是属于彻头彻尾的工具控. 假如有 ...

  7. JavaScript 作用域和闭包——另一个角度:扩展你对作用域和闭包的认识【翻译+整理】

    原文地址 --这篇文章有点意思,可以扩展你对作用域和闭包的认识. 本文内容 背景 作用域 闭包 臭名昭著的循环问题 自调用函数(匿名函数) 其他 我认为,尝试向别人解释 JavaScript 作用域和 ...

  8. 为javascript设置默认参数值

    javascript(js)中如何为函数设置默认参数值,下面提供几种方法供参考. 第一种方法: function example(a,b){ var a = arguments[0] ? argume ...

  9. 电脑的fn锁,f1-f12与功能键 互换

    提要: 有些机子特别逆天,比如说Thinkpad e系列.好好的f1-f12一定要加上fn才能按出来,默认的是画在上面的功能键,作为娱乐来说其实是还不错的,但是像我等程序员就觉得特别逆天了.你有两个选 ...

  10. Node,Sockets,Cores,Threads

    http://fishcried.com/2015-01-09/cpu_topology/ http://kodango.com/cpu-topology http://www.udpwork.com ...