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 ...
随机推荐
- capwap学习笔记——初识capwap(五)
3. CAPWAP Binding for IEEE 802.11 ¢ CAPWAP协议本身并不包括任何指定的无线技术.它依靠绑定协议来扩展对特定无线技术的支持. ¢ RFC5416就是用来扩展CAP ...
- Python 编码风格指南
原文:http://python.jobbole.com/84618/ 本文超出 PEP8 的范畴以涵盖我认为优秀的 Python 风格.本文虽然坚持己见,却不偏执.不仅仅涉及语法.模块布局等问题,同 ...
- Redis集群搭建最佳实践
要搭建Redis集群.首先得考虑以下的几个问题; Redis集群搭建的目的是什么?或者说为什么要搭建Redis集群? Redis集群搭建的目的事实上也就是集群搭建的目的.全部的集群主要都是为了解决一个 ...
- 在Excel中输入超过10的带圈数字
通过改变字体,可以在excel中输入1-20的带圈数字.对于某些人这些还不够用,那怎么办呢? 有了下面这个不知道是哪个大神做的字体,你就可以直接输到100啦 将字体文件文件粘贴至“C:\WINDOWS ...
- Android基础(五) Service全解析----看不见的Activity
一.服务的介绍: 作为Android四大组件之中的一个,Service(服务)也常常运用于我们的日常使用中,它与Activity的差别在于:Service一直在后台执行.没实用户界面.所以绝不会到前台 ...
- npm - 部分常用命令(笔记)
<!-- npm部分简写: ci -> package-lock.json ls -> list pkg -> package i -> install -g -> ...
- Active Directoty域服务安装
运行dcpromo命令,打开“Active Directoty域服务安装向导”
- NGINX源码分析——概览
一.概况 Nginx可以开启多个进程,每个进程拥有最大上限128个子线程以及一定的可用连接数.最大客户端连接数等于进程数与连接数的乘积,连接是在主进程中初始化的,一开始所有连接处于空闲状态.每一个客户 ...
- 方法(method)和函数(function)有什么区别?
方法(method)和函数(function)有什么区别? 定义和参数区别 函数是独立的功能,与对象无关,需要显示的传递数据 方法与对象和类相关,依赖对象而调用,可以直接处理对象上的数据,也就是隐式传 ...
- POJ 1548 Robots(最小路径覆盖)
POJ 1548 Robots 题目链接 题意:乍一看还以为是小白上那题dp,事实上不是,就是求一共几个机器人能够覆盖全部路径 思路:最小路径覆盖问题.一个点假设在还有一个点右下方,就建边.然后跑最小 ...