CF45J.Planting Trees
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Vasya is a Greencode wildlife preservation society proponent. One day he found an empty field nobody owned, divided it into n × m squares and decided to plant a forest there. Vasya will plant nm trees of all different heights from 1 to nm. For his forest to look more natural he wants any two trees growing in the side neighbouring squares to have the absolute value of difference in heights to be strictly more than 1. Help Vasya: make the plan of the forest planting for which this condition is fulfilled.
瓦西娅是“绿色编码”野生动物保护协会的支持者。一天,他发现了一块无人认领的空地,将其划分为 n×m 个方格,并决定在此种植一片森林。瓦西娅将种植 nm 棵树,其高度互不相同,恰好为 1 到 nm 的所有整数。为了让森林看起来更自然,他要求:任意两棵位于相邻(共享一条边)方格中的树,其高度之差的绝对值严格大于 1。请帮助瓦西娅设计一种满足该条件的植树方案。
输入格式
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100) — the number of rows and columns on Vasya's field
第一行包含两个以空格分隔的整数 n 和 m(1 ≤ n, m ≤ 100)——分别表示瓦西亚田地的行数和列数。
输出格式
If there's no solution, print -1. Otherwise, print n lines containing m numbers each — the trees' planting plan. In every square of the plan the height of a tree that should be planted on this square should be written. If there are several solutions to that problem, print any of them.
如果没有解,输出 -1。否则,输出 n 行,每行包含 m 个数字——即树木的种植方案。在方案的每个方格中,应填入该方格上需种植的树的高度。若该问题有多个解,输出任意一个即可。
输入输出样例
输入#1
2 3
输出#1
3 6 2 5 1 4
输入#2
2 1
输出#2
-1
输入解题思路,AI测评打分。不知道怎么写?