HDU
来源:互联网 发布:数码大师软件多大 编辑:程序博客网 时间:2024/05/16 04:57
思路: 按照单价升序排序,依次买就行。
AC代码
#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>#include <utility>#include <string>#include <iostream>#include <map>#include <set>#include <vector>#include <queue>#include <stack>using namespace std;#pragma comment(linker, "/STACK:1024000000,1024000000") #define eps 1e-10#define inf 0x3f3f3f3f#define PI pair<int, int> typedef long long LL;const int maxn = 1000 + 5;struct node{int cost, w;bool operator < (const node& p) const {return cost < p.cost;}}a[maxn];int main() {int T, n, m;scanf("%d", &T);while(T--) {scanf("%d%d", &m, &n);for(int i = 0; i < n; ++i) scanf("%d%d", &a[i].cost, &a[i].w);sort(a, a+n);double ans = 0;for(int i = 0; i < n; ++i) {if(m > a[i].cost * a[i].w) {ans += a[i].w;m -= a[i].cost * a[i].w;}else {ans += 1.0 * m / a[i].cost;break;}}printf("%.2lf\n", ans);}return 0;}
如有不当之处欢迎指出!
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- mysql-常规优化思路
- BZOJ P2081[Poi2010]Beads
- s标签s:select下拉列表的使用
- org.apache.ibatis.binding.BindingException: Parameter 'List' not found. Available parameters are [l
- CSDN如何转载别人的文章
- HDU
- RMAN表空间时间点恢复,TSPITR
- math.h头文件中声明了常用的一些数学运算(pow, sqrt, ceil,floor)
- 关于数据库删除
- 欢迎使用CSDN-markdown编辑器
- (一)C++类型增强
- 2012年第三届蓝桥杯C/C++程序设计本科B组省赛题目 微生物增殖 结果填空
- Qt在Windows下的三种编程环境搭建
- 电脑端操作Android手机截图并上传