CF1179B.Tolik and His Uncle
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.
After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.
In this task you are given a cell field n⋅m, consisting of n rows and m columns, where point's coordinates (x,y) mean it is situated in the x-th row and y-th column, considering numeration from one (1≤x≤n,1≤y≤m). Initially, you stand in the cell (1,1). Every move you can jump from cell (x,y), which you stand in, by any non-zero vector (dx,dy), thus you will stand in the (x+dx,y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).
Tolik's uncle is a very respectful person. Help him to solve this task!
今天早上,托利克突然意识到:自己在睡觉时想出了一个绝妙的问题,非常适合 Codeforces!但此时“讨论题目”项目(英文版)尚未诞生,于是他决定先测试一下这个问题,并向自己的叔叔求助。
经过长时间的思考,托利克的叔叔始终没有想出解决方法。然而,他不想让托利克知道自己解不出这道题,于是只好向你求助,请你帮忙解决这个问题。
本题中,你将面对一个 n×m 的网格,该网格由 n 行和 m 列组成;其中某格坐标 (x,y) 表示它位于第 x 行、第 y 列(行列编号均从 1 开始,即 1≤x≤n,1≤y≤m)。初始时,你位于单元格 (1,1)。每一步,你可以从当前所在单元格 (x,y) 沿任意非零向量 (dx,dy) 跳跃,从而到达新位置 (x+dx,y+dy)。显然,你不能跳出网格边界;此外,还有一个重要限制——同一个向量 (dx,dy) 不允许使用两次。你的目标是恰好访问网格中的每个单元格一次(起始单元格 (1,1) 视为已访问)。
托利克的叔叔是一位非常受人尊敬的人。请帮助他解决这个问题!
输入格式
The first and only line contains two positive integers n,m (1≤n⋅m≤106) — the number of rows and columns of the field respectively.
第一行且唯一一行包含两个正整数 n,m(1≤n⋅m≤106),分别表示场地的行数和列数。
输出格式
Print "-1" (without quotes) if it is impossible to visit every cell exactly once.
Else print n⋅m pairs of integers, i-th from them should contain two integers xi,yi (1≤xi≤n,1≤yi≤m) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.
Notice that the first cell should have (1,1) coordinates, according to the statement.
如果无法恰好访问每个格子一次,则输出 -1(不带引号)。
否则,输出 n⋅m 对整数,其中第 i 对应为两个整数 xi,yi(满足 1≤xi≤n,1≤yi≤m),表示按访问顺序经过的格子坐标,要求所有格子互不相同,且相邻格子之间的跳跃向量也互不相同。
注意:根据题意,第一个格子的坐标必须为 (1,1)。
输入输出样例
输入#1
2 3
输出#1
1 1 1 3 1 2 2 2 2 3 2 1
输入#2
1 1
输出#2
1 1
说明/提示
The vectors from the first example in the order of making jumps are (0,2),(0,−1),(1,0),(0,1),(0,−2).
第一个示例中的向量按跳跃顺序排列为 (0,2),(0,−1),(1,0),(0,1),(0,−2)。
输入解题思路,AI测评打分。不知道怎么写?