You programmers are lucky! You don't have to deal with these terrible people – designers… This story happened with me not so long ago. We had an order from a company building a new hotel. One day they brought a sketch to our workshop. They said that THIS was invented by a very cool designer. They said they had paid heaps of money for THIS. So, THIS had to be built. In general, THIS was not a very complex thing. It was just a square set of shelves where a porter puts guests' mail. Usual hotels have usual stands with shelves for this purpose. But this cool designer had turned everything upside down! To be more precise, not exactly upside down, but upon a corner. Moreover, the cells should be numbered from the right to the left, from the top to the bottom, looking at THIS, staying on its corner, of course. Tell me please, how can the master attach the labels with numbers to THIS? He will look on the shelves, staying normally on its side, you know. He will get tangled on the fourth label already! I will get tangled on the seventh, myself… Actually one should make such designers to label the shelves themselves.

— Oh! You are the cool programmer, I know. Couldn’t you help me? I need just a printout of the table with an arrangement of the labels in the cells. But not in such way as THIS will hang on the wall, but as THIS stands on the table of my workshop. Yes, I understand that you are busy, but you are busy every time! Preparations to the Ural Championship, tests, solutions… So what? If you can’t do it yourself – entrust your competitors with this task. They are the best programmers all over the world, aren’t they? I don’t believe that they couldn’t print the desired table having the size of the square! I would never believe it! So… Excellent! I will take the desired printout away after the contest.

Input

The input consists of the only one integer N (1 ≤ N ≤ 100), which is the size of the square.

Output

You are to write a program that outputs the table of numbers, as they would be arranged when THIS would stand in the workshop. The label with number 1 should be in the upper right corner and other numbers should be arranged along the diagonals from the top to the bottom. The label with the last number (N*N) should be in the lower left corner.

Sample

input output
3
4 2 1
7 5 3
9 8 6
Problem Author: Stanislav Vasilyev Problem Source: VIII Collegiate Students Urals Programming Contest. Yekaterinburg, March 11-16, 2004
// Ural Problem 1319. Hotel
// Verdict: Accepted
// Submission Date: 01:06:08 16 Jan 2014
// Run Time: 0.031s
//
// 版权所有(C)acutus (mail: acutus@126.com)
// 博客地址:http://www.cnblogs.com/acutus/// [解题方法]
// 简单题,直接找矩阵规律即可 #include<stdio.h> int a[][]; void solve()
{
int N, i, j, k, M, t;
scanf("%d", &N);
M = N * (N + ) / ;
t = ;
j = ; k = ;
while(k <= M) {
for(j = N - ; j >= ; j--) {
t = j;
i = ;
while(t <= N - ) {
a[i++][t++] = k++;
}
}
}
for(i = ; i < N; i++) {
t = i;
for(j = ; j < N - i; ){
a[t++][j++] = k++;
}
}
for(i = ; i < N; i++) {
for(j = ; j < N; j++) {
if(j == ) printf("%d", a[i][j]);
else printf(" %d", a[i][j]);
}
printf("\n");
}
} int main()
{
solve();
return ;
}

Ural 1319 - Hotel的更多相关文章

  1. POJ 3667 Hotel(线段树 区间合并)

    Hotel 转载自:http://www.cnblogs.com/scau20110726/archive/2013/05/07/3065418.html [题目链接]Hotel [题目类型]线段树 ...

  2. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  3. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  4. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  5. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

  6. ural 2069. Hard Rock

    2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...

  7. ural 2068. Game of Nuts

    2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...

  8. ural 2067. Friends and Berries

    2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...

  9. ural 2066. Simple Expression

    2066. Simple Expression Time limit: 1.0 secondMemory limit: 64 MB You probably know that Alex is a v ...

随机推荐

  1. Python 第三篇(上):python文件基础操作、json模块、lambda、map、filter、reduce和函数位置参数

    python一切皆对象,linux一切皆文件,python操作文件是很常见的O/I操作,其内置来open()函数可以完成文件的基本操作: 一:使用内置open()函数操作文件,基本语法如下: with ...

  2. tomcat 会话超时设置

    1.为单个WEB设置SESSION 在WEB.XML中添加 xml 代码 <session-config> <session-timeout>15</session-ti ...

  3. Trie三兄弟——标准Trie、压缩Trie、后缀Trie

    1.Trie导引 Trie树是一种基于树的数据结构,又称单词查找树.前缀树,字典树,是一种哈希树的变种.应用于字符串的统计与排序,经常被搜索引擎系统用于文本词频统计.用于存储字符串以便支持快速模式匹配 ...

  4. BZOJ 3038 上帝造题的七分钟2 (并查集+树状数组)

    题解:同 BZOJ 3211 花神游历各国,需要注意的是需要开long long,还有左右节点需要注意一下. #include <cstdio> #include <cmath> ...

  5. 框架技术--Spring自动加载配置

    今天项目中遇到一个问题,一个方法在服务启动后会自动被执行,查看了下配置未发现有定时的配置.但是后来发现是spring配置了启动时默认加载了方法. 代码: <?xml version=" ...

  6. MessageDigest简单介绍

    本文博客原文 參考文章:http://blog.sina.com.cn/s/blog_4f36423201000c1e.html 一.概述 java.security.MessageDigest类用于 ...

  7. fopen()函数

    1.2 文件的输入输出函数 键盘.显示器.打印机.磁盘驱动器等逻辑设备, 其输入输出都能够通过文件管理的方法来完毕.而在编程时使用最多的要算是磁盘文件, 因此本节主要以磁盘文件为主, 具体介绍Turb ...

  8. 【转】CTE(公用表表达式)

    本文转自:爽朗的微笑  http://www.cnblogs.com/shuangnet/archive/2013/03/22/2975929.html 公用表表达式 (CTE) 具有一个重要的优点, ...

  9. Extjs 3.0 htmleditor实现插入图片功能

    首先感谢前辈们的无私奉献.贴出参考地址 http://zhidao.baidu.com/link?url=Q0ZM405OFNy_xAHSut9TepRJxgXCxFayQttrQz1N82dlA1_ ...

  10. 「C」 数组、字符串、指针

    一.数组 (一)数组 概念:用来存储一组数据的构造数据类型 特点:只能存放一种类型的数据,如全部是int型或者全部是char型,数组里的数据成为元素. (二)数组的定义 格式: 类型 数组名[元素个数 ...