【NOIP2016】【Luogu1909】买铅笔(模拟)

problem

  • 给你3种组合,每种有x只笔和售价y元。
  • 选择1种组合,使得买n支笔的总消费最少。
  • 求总消费。

solution

  • 我还是太天真了,,,第一眼看过去背包。。。
    然而,题目告诉我们P老师决定只买同一种包装的铅笔
  • 算的时候注意向上取整(不足5包要当5包算

codes

#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n, ans=(int)1e9;  cin>>n;
    for(int i = 1; i <= 3; i++){
        int x, y;  cin>>x>>y;
        int t = n/x*y; if(n%x!=0)t+=y;
        ans = min(ans, t);
    }
    cout<<ans<<'
';
    return 0;
}
原文地址:https://www.cnblogs.com/gwj1314/p/9444645.html