Journey

题意翻译

## 题目描述 你现在处于 $n\times m$ 的矩阵中 $(1,1)$ 这个点上。你现在的目标是走完全部点且不能走重复的点。你每一次只能移动 $1$ 格。 但是,你可以在迷宫中的任意一点放置一个传送门,这个传送门可以将你单向传送到一个传送门标记的点。现在求放置传送门次数最少的移动方案。 ## 输入格式 输入共 $1$ 行,输入 $n$ 和 $m$。 ## 输出格式 第一行输出传送门的最少放置个数 $k$。 接下来 $k$ 行,每行输出一组 $x_0,y_0,x_2,y_1$,表示有一个 $(x_0,y_0)\to(x_1,y_1)$ 的传送门。 接下来 $nm+1$ 行,每行输出此时所在的点的坐标。 ## 数据范围 对于 $100\%$ 的数据,保证 $1\le n,m\le100$,$n\times m>1$。 ## 提醒 $(1,1)$ 会在起始与末尾各出现一次! --- Translated by [残阳如血](/user/726139)。

题目描述

The territory of Berland is represented by a rectangular field $ n×m $ in size. The king of Berland lives in the capital, located on the upper left square $ (1,1) $ . The lower right square has coordinates $ (n,m) $ . One day the king decided to travel through the whole country and return back to the capital, having visited every square (except the capital) exactly one time. The king must visit the capital exactly two times, at the very beginning and at the very end of his journey. The king can only move to the side-neighboring squares. However, the royal advise said that the King possibly will not be able to do it. But there is a way out — one can build the system of one way teleporters between some squares so that the king could fulfill his plan. No more than one teleporter can be installed on one square, every teleporter can be used any number of times, however every time it is used, it transports to the same given for any single teleporter square. When the king reaches a square with an installed teleporter he chooses himself whether he is or is not going to use the teleport. What minimum number of teleporters should be installed for the king to complete the journey? You should also compose the journey path route for the king.

输入输出格式

输入格式


The first line contains two space-separated integers $ n $ and $ m $ ( $ 1<=n,m<=100,2<= $ $ n $ $ · $ $ m $ ) — the field size. The upper left square has coordinates $ (1,1) $ , and the lower right square has coordinates of $ (n,m) $ .

输出格式


On the first line output integer $ k $ — the minimum number of teleporters. Then output $ k $ lines each containing 4 integers $ x_{1} $ $ y_{1} $ $ x_{2} $ $ y_{2} $ ( $ 1<=x_{1},x_{2}<=n,1<=y_{1},y_{2}<=m $ ) — the coordinates of the square where the teleporter is installed ( $ x_{1},y_{1} $ ), and the coordinates of the square where the teleporter leads ( $ x_{2},y_{2} $ ). Then print $ nm+1 $ lines containing 2 numbers each — the coordinates of the squares in the order in which they are visited by the king. The travel path must start and end at $ (1,1) $ . The king can move to side-neighboring squares and to the squares where a teleporter leads. Besides, he also should visit the capital exactly two times and he should visit other squares exactly one time.

输入输出样例

输入样例 #1

2 2

输出样例 #1

0
1 1
1 2
2 2
2 1
1 1

输入样例 #2

3 3

输出样例 #2

1
3 3 1 1
1 1
1 2
1 3
2 3
2 2
2 1
3 1
3 2
3 3
1 1