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 ...
随机推荐
- awk的基本使用方法
awk是处理文本文件的一个应用程序,几乎所有 Linux 系统都自带这个程序. 它依次处理文件的每一行,并读取里面的每一个字段.对于日志.CSV 那样的每行格式相同的文本文件,awk可能是最方便的工具 ...
- Discuz常见小问题-如何取消帖子置顶
定位到一个帖子,然后顶部会有置顶的选项,还是勾选置顶,后面下拉列表选择无,然后点击确定,提示解除置顶
- C/S通信模型与B/S通信模型介绍
1.客户端与服务器之间的通信模型 基于Socket连接的客户端与服务器之间的通信模型图如上图所示,整个通信过程如下所示: (1) 服务器端首先启动监听程序,对指定的端口进行监听,等待接收客户端的连接请 ...
- jQuery clearQueue
clearQueue()方法与clearQueue()方法结合: .clearQueue()可用于删除通过.queue()方法添加到通用jQuery序列的任何函数. 示例: <!DOCTYPE ...
- Linux中最常用的JAVA_HOME配置
一.配置 更改下面配置中的JAVA_HOME路径为你的路径. export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.144-0.b01.el7_ ...
- Stingray验证机制
Filter 系统中的验证使用的是Filter库来完成,利用Filter配置几个属性和参数就实现了表单验证,简化了工作.基本原理很简单,在onload之后按照属性查找元素,然后绑定相应的change/ ...
- PPT里面的背景音乐找不到?
ppt,找不到播放器,却有音乐播放!如何实现? 原来是在幻灯片切换处的音效添加的音乐~ 文章来源:刘俊涛的博客 欢迎关注,有问题一起学习欢迎留言.评论
- 请指出document load和document ready的区别?
共同点:这两种事件都代表的是页面文档加载时触发. 异同点: ready 事件的触发,表示文档结构已经加载完成(不包含图片等非文字媒体文件). onload 事件的触发,表示页面包含图片等文件在内的所有 ...
- js 原型链 prototype __proto__
1.说明 函数(Function)才有prototype属性,对象(除Object)拥有__proto__. 2.prototype与__proto__区别 示例: <!DOCTYPE html ...
- 【shell】shell基础脚本合集
1.向脚本传递参数 #!/bin/bash #功能:打印文件名与输入参数 #作者:OLIVER echo $0 #打印文件名 echo $1 #打印输入参数 执行结果: 2.在脚本中使用参数 #!/b ...