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. 转:查看linux系统版本号

    转自: http://blog.csdn.net/zhuying_linux/article/details/6859286 lsb_release -a

  2. template.helper 多参数

    <script type="text/html" id="text4"> {{detail name classInfo schoolInfo}} ...

  3. “图片+标签”的社交玩法已经被验证?nice 宣布获得新一轮3600万美元融资【转载+整理】

    原文地址 有次上班做公交,期间听到一个老太太说:"我加你微信啊--",还有一次去看老中医,并交换了电话,可当我回去后发现这个大夫竟然加了我微信--这些都令我有点吃惊,连60.70岁 ...

  4. MySQL查询当天、本周,本月,上一个月的数据

    QUARTER)); ; MONTH),'%Y-%m') select * from user where DATE_FORMAT(pudate,'%Y%m') = DATE_FORMAT(CURDA ...

  5. Mybatis拦截器实现SQL性能监控

    Mybatis拦截器只能拦截四类对象,分别为:Executor.ParameterHandler.StatementHandler.ResultSetHandler,而SQL数据库的操作都是从Exec ...

  6. spring结合mybatis实现数据库读写分离

    随着系统用户访问量的不断增加,数据库的频繁访问将成为我们系统的一大瓶颈之一.由于项目前期用户量不大,我们实现单一的数据库就能完成.但是后期单一的数据库根本无法支撑庞大的项目去访问数据库,那么如何解决这 ...

  7. JavaScript 时间、格式、转换及Date对象总结

    悲剧的遇到问题,从前台得到时间,“Tue Jan 29 16:13:11 UTC+0800 2008”这种格式的,想再后台解析成想要的格式,但是在后台就是解析不了SimpleDateFormat也试着 ...

  8. 【SCM】关于Gradle与maven的几篇文章

    Gradle官方文档:https://docs.gradle.org/current/userguide/installation.html#sec:download 使用 Gradle 命令行:ht ...

  9. oracle数据分组

    一,什么是分组函数 分组函数作用于一组数据,并对一组数据返回一个值 二,分组函数类型 Avg ,count,max,min,stddev(标准方差),sum. 函数名称 函数描述 Count 返回找到 ...

  10. 微信小程序 - 自定义switch切换(示例)

    点击下载:switch示例 ,适用于表单,官方switch 说明 .