A. Candy Bags
1 second
256 megabytes
standard input
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.
The single line contains a single integer n (n is even, 2 ≤ n ≤ 100) — the number of Gerald's brothers.
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.
2
1 4
2 3
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的更多相关文章
- Candy Bags
读懂了题就会发现这是个超级大水题 Description Gerald has n younger brothers and their number happens to be even. One ...
- F - Candy Bags
A. Candy Bags time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 334A Candy Bags
A. Candy Bags time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- codeforces A. Candy Bags 解题报告
题目链接:http://codeforces.com/contest/334/problem/A 题意:有n个人,将1-n袋(第 i 袋共有 i 颗糖果,1<= i <=n)所有的糖 ...
- codeforces 334A - Candy Bags
忘了是偶数了,在纸上画奇数画了半天... #include<cstdio> #include<cstring> #include<cstdlib> #include ...
- Candy Distribution
Kids like candies, so much that they start beating each other if the candies are not fairly distribu ...
- CodeForces Round 194 Div2
A. Candy Bagstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputs ...
- 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 ...
- [LeetCode] Candy 分糖果问题
There are N children standing in a line. Each child is assigned a rating value. You are giving candi ...
随机推荐
- ASP.NET MVC 重命名[命名空间]而导致的错误及发现的ASP.NET MVC Bug一枚
使用VS2012新建了一个Asp.net mvc5的项目,并把项目的命名空间名称更改了(Src更改为UXXXXX),然后就导致了以下错误 刚开始以后是项目的属性中的命名空间没有更改过来的问题,但我在重 ...
- 解决Ubuntu/debian的Apt-get 由于依赖关系安装失败的问题
The following packages have unmet dependencies: libssl-dev: Depends: libssl0.9.8 (= 0.9.8k-7ubuntu8) ...
- 如何检查显卡类型,DirectX和OpenGL的版本
How To: Check the graphics card type and OpenGL version From: http://support.esri.com/technical-arti ...
- rabbitMQ在linux上安装
语言环境安装 一.编译安装方式 1.依赖环境的安装-如果需要用编译安装erlang语言环境,需要安装C++编译. yum -y install make gcc gcc-c++ kernel-deve ...
- Python连接MySQL的实例代码
Python连接MySQL的实例代码 MySQLdb下载地址:http://sourceforge.net/projects/mysql-python/ 下载解压缩后放到%Python_HOME% ...
- WinForm 之 程序退出
一.关闭窗体 在c#中退出WinForm程序包括有很多方法,如:this.Close(); Application.Exit();Application.ExitThread(); System.En ...
- 算法笔记_227:填写乘法算式(Java)
目录 1 问题描述 2 解决方案 1 问题描述 观察下面的算式: * * × * * = * * * 它表示:两个两位数字相乘,结果是3位数.其中的星号(*)代表任意的数字,可以相同,也可以不同, ...
- Eclipse 写 Python的一些小问题
- 解决java网络编程IPv6问题
如果系统中开启了IPV6协议(比如window7),java网络编程经常会获取到IPv6的地址,这明显不是我们想要的结果,搜索发现很多蹩脚的做法是:禁止IPv6协议.其实查看官方文档有详细的说明: j ...
- SSH黄金参数
ssh -o ConnectTimeout=3 -o ConnectionAttempts=5 -o PasswordAuthentication=no -o StrictHostKeyCheckin ...