杭电acm2111
2015-11-02 13:09
281 查看
贪心
#include <stdio.h> #include <algorithm> using namespace std; struct jewelry { int price; int volume; bool operator < (const jewelry &A) const { return price > A.price; } }buf[101]; int main() { int v, n, i, ans, ids; while(~scanf("%d", &v) && v) { scanf("%d", &n); for(i=0; i<n; i++) scanf("%d%d", &buf[i].price, &buf[i].volume); sort(buf, buf+n); ids = 0; ans = 0; while(v>0 && ids<n) { if(v>=buf[ids].volume) { v -= buf[ids].volume; ans += buf[ids].price * buf[ids].volume; } else { ans += v * buf[ids].price; v = 0; } ids ++; } printf("%d\n", ans); } return 0; }
相关文章推荐
- 一个中断异常出现
- (Alpha)Let's-典型用户和场景&功能规格说明书
- Asp.net中的页面跳转及post数据
- 实现一个函数,将一个字符串中的空格替换成“ % 20”
- 高级C语言教程
- jquery Tab默认情况下自动切换
- effective c++ 将成员变量声明为private
- 工作队列(workqueue)
- 【华山杯】逆向300_WriteUp
- Numpy 数组的切片操作
- C语言数据结构之图的遍历
- 线性表的实现(二)链式存储
- EXCEL工作表保护密码忘记,撤销保护攻略
- [UVA 11762] Race to 1
- C++的for语句详解
- linux patch 命令小结
- http协议学习笔记
- [leetcode] Find the Duplicate Number
- 《深入理解Linux内核》软中断/tasklet/工作队列
- sqlite3 数据库实战并测试