题解:P13717 [GCPC 2024] Bookshelf Bottleneck
题意简述
给你
思路
对于每个立方体,我们要在能放的情况下使得:
- 把尽可能大的一条边当作高。
- 把尽可能小的一条边当作宽。
根据这个贪心策略,用几个判断就能过了。
::::warning[注意]{open}
要开 long long,int。
::::
代码
#include <iostream>
#define int long long //注意
using namespace std;
int n, h, ans;
signed main() {
cin >> n >> h;
while (n--) {
int x, y, z;
cin >> x >> y >> z;
//相当于排序
int a = min(x,min(y,z)), c = max(x,max(y,z)), b = x+y+z-a-c;
//根据贪心策略进行选择
if (c <= h) ans += a;
else if (b <= h) ans += a;
else if (a <= h) ans += b;
else { //如果三条边都放不了,说明不合法
puts("impossible");
return 0;
}
}
cout << ans;
return 0;
}