Milk Pails
问题描述
USACO 2016 February Contest, Bronze Problem 1. Milk Pails https://usaco.org/index.php?page=viewproblem2&cpid=615
给定 ,求 不超过 的最大值, 任意。
样例
输入
17 25 77输出
76思路
的范围为 至 , 的范围为 至 。 遍历 和 ,如果 不超过 ,则 更新为最大值。
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
freopen("pails.in", "r", stdin);
freopen("pails.out", "w", stdout);
int x, y, m;
cin >> x >> y >> m;
int ans = 0;
for(int i = 0; i <= m / x; i++){
for(int j = 0; j <= m / y; j++){
int now = i * x + j * y;
if(now <= m){
ans = max(now, ans);
}
}
}
cout << ans;
return 0;
}Milk Pails
https://mingsm17518.github.io/2026/04/30/算法学习/03_Bronze/01_Complete_Search/01_Milk Pails/