【NOIP2016】【Luogu1909】买铅笔(模拟)
【摘要】
problem
给你3种组合,每种有x只笔和售价y元。选择1种组合,使得买n支笔的总消费最少。求总消费。
solution
我还是太天真了,,,第一眼看过去背包。。。 然而,题目告诉我们P老师决定...
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<<'\n';
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
文章来源: gwj1314.blog.csdn.net,作者:小哈里,版权归原作者所有,如需转载,请联系作者。
原文链接:gwj1314.blog.csdn.net/article/details/80951471
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)