QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 256 MB Total points: 100

#12729. 折叠

Statistics

如你所记得的那样,Alex 热衷于折纸。她从正方形转向了长方形,而长方形要难掌握得多。她现在主要想确定将一个 $W \times H$ 的长方形变换为一个 $w \times h$ 的长方形所需的最少折叠次数。每次折叠的结果也必须是长方形,因此只允许进行平行于长方形边的折叠。

请帮助 Alex 编写一个程序,确定所需的最少折叠次数。

输入格式

输入的第一行包含两个整数 $W$ 和 $H$,表示初始长方形的尺寸。第二行包含另外两个整数 $w$ 和 $h$,表示目标长方形的尺寸($1 \le W, H, w, h \le 10^9$)。

输出格式

输出一个整数,表示将初始长方形变换为目标长方形所需的最少折叠次数。

如果无法完成所需的变换,输出 $-1$。

样例

样例输入 1

2 7
2 2

样例输出 1

2

样例输入 2

10 6
4 8

样例输出 2

2

样例输入 3

5 5
1 6

样例输出 3

-1

说明

在第一个样例中,你应该将 $2 \times 7$ 的长方形折叠为 $2 \times 4$,然后再折叠为 $2 \times 2$。

在第二个样例中,你应该将 $10 \times 6$ 的长方形折叠为 $10 \times 4$,然后折叠为 $8 \times 4$,并将其旋转为 $4 \times 8$。

在第三个样例中,无法将 $5 \times 5$ 的长方形折叠为 $1 \times 6$ 的长方形(请记住,折叠必须平行于长方形的边)。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.