Files
python/TangDou/LanQiaoBei/LanQiaoBei13ShengSai_ZJ_I/BC4_2.cpp

37 lines
825 B
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n, k;
int w[N], h[N];
int tmax;
/*
2 6
4 3
5 4
答案:
2
*/
int main() {
cin >> n >> k; // n个矩形 ,要剪出k个正方形,要求正方形的边长最大
for (int i = 1; i <= n; i++) {
cin >> w[i] >> h[i];
tmax = max(min(w[i], h[i]), tmax); // 最小当中的最大
}
//从tmax->1,尝试i能不能整出来k个,如果小于k就continue,否则break
bool flag = false;
for (int i = tmax; i >= 1; i--) {
int cnt = 0;
for (int j = 1; j <= n; j++)
cnt += (w[j] / i) * (h[j] / i);
if (cnt == k) {
cout << i << endl;
flag = true;
break;
}
}
if (!flag) cout << -1 << endl;
return 0;
}