You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
825 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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