问如何切蛋糕可以保证分开两个点,就是让切开后的每块蛋糕都有一个点
就是沿着这两个点所在的矩形的对角线切就可以
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
freopen("folding.in", "r",stdin);
freopen("folding.out", "w", stdout);
// freopen("IN.txt", "r", stdin);
long long n, m, a, b;
// ios::sync_with_stdio(0);
while (cin >> a >> b >> m >> n) {
if (a > b) swap(a, b); // a < b
if (m > n) swap(m, n); // m < n
if (n > b || m > a) {
cout << -1 << endl;
}
else {
long long ans1 = 0, ans2 = 0;
long long t1, t2;
t1 = m, t2 = n;
while (t1 < a) {
t1 *= 2;
ans1++;
}
while (t2 < b) {
t2 *= 2;
ans1++;
}
t1 = n, t2 = m;
while (t1 < a) {
t1 *= 2;
ans2++;
}
while (t2 < b) {
t2 *= 2;
ans2++;
}
if (m <= b && n <= a) {
cout << min(ans1, ans2) << endl;
}
else {
cout << ans1 << endl;
}
}
}
return 0;
}