Files
python/TangDou/LanQiaoBei/LanQiaoBei13ShengSai_ZJ_I/BC4_2.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

37 lines
825 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}