FatMouse' Trade
/*
problem: FatMouse' Trade
this is greedy problem.
firstly:we should calculate the average J[i]/F[i] and sort it
secondly: according to the m and choose the most high ones
*/
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std; struct cell
{
double j;
double f;
double rate;
};
bool cmp(cell x,cell y)
{
return x.rate > y.rate;
}
int main()
{
int m,n;
cell temp;
vector<cell> vec;
while (scanf("%d%d", &m, &n) != EOF)
{
if ((m == -1)&&(n == -1))
break;
double count = 0.0;
while (n--)
{
cin>>temp.j>>temp.f;
if (temp.f != 0)
{
temp.rate = (double)temp.j/temp.f;
vec.push_back(temp);
}
else
{
count += temp.j;
} }
sort(vec.begin(), vec.end(), cmp);
for (int i = 0; (i < vec.size())&&(m > 0); i++)
{
if (m-vec[i].f >= 0)
{
count += vec[i].j;
m -= vec[i].f;
}
else
{
//count += (double)((double)(m/vec[i].f))*vec[i].j;
double temp1 = (double)m/vec[i].f;
count += temp1*vec[i].j;
m = 0;
}
}
vec.clear();
printf("%.3f\n",count);
}
}
/*此题除了要满足例子以外,还要满足一些条件才能真正算ac:
0 1
1 0
1.000 1 0
0.000 5 4
10000 5
2000 2
100 0
300 0
10400.000 数据类型用double,就这样*/
FatMouse' Trade的更多相关文章
- Hdu 1009 FatMouse' Trade
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- hdu 1009:FatMouse' Trade(贪心)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- Hdu 1009 FatMouse' Trade 分类: Translation Mode 2014-08-04 14:07 74人阅读 评论(0) 收藏
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 1009 FatMouse' Trade
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU1009 FatMouse' Trade
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1009 FatMouse' Trade(贪心)
FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the ...
- FatMouse' Trade -HZNU寒假集训
FatMouse' Trade FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the wa ...
- FatMouse' Trade(杭电ACM---1009)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- Hdu 1009 FatMouse' Trade 2016-05-05 23:02 86人阅读 评论(0) 收藏
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
随机推荐
- OpenGL超级宝典第5版&&基础渲染
1.OpenGL查询拓展机制是否被支持 gltools函数库: int gltIsExtSupported(const char *extension) { #ifndef OPENGL_ES GLi ...
- Spring 中context.start作用
我们经常会看到 如下代码 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(configPath. ...
- MFC DLL 资源模块句柄切换[转]
以前写MFC的DLL的时候,总会在自动生成的代码框架里看到提示,需要在每一个输出的函数开始添加上 AFX_MANAGE_STATE(AfxGetStaticModuleState()).一直不明白这样 ...
- ACM1995
/* 汉诺塔V Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- ubuntu java jdk安装及环境变量设置
1.下载jdk1.7.0_79 (32位操作系统)jdk-7u79-linux-i586.tar.gz (64位操作系统)jdk-7u79-linux-x64.tar.gz http://www.or ...
- Windows Azure中的配置管理
最近一直在做项目迁移的工作,由传统的ASP.NET转到Windows Azure,这里介绍一下Azure的配置管理.在传统的WinForm或ASP.NET项目下,配置文件为web.config(app ...
- URAL 2040 Palindromes and Super Abilities 2 (回文自动机)
Palindromes and Super Abilities 2 题目链接: http://acm.hust.edu.cn/vjudge/contest/126823#problem/E Descr ...
- 第十五章 String讲解
package ch15; import java.util.Scanner; public class Test { public static void main(String[] args) { ...
- C++成员变量、构造函数的初始化顺序
一.C++成员变量初始化 1.普通的变量:一般不考虑啥效率的情况下 可以在构造函数中进行赋值.考虑一下效率的可以再构造函数的初始化列表中进行 2.static 静态变量(本地化数据和代码范围): st ...
- 一个 C# 获取高精度时间类(调用API QueryP*)
如果你觉得用 DotNet 自带的 DateTime 获取的时间精度不够,解决的方法是通过调用 QueryPerformanceFrequency 和 QueryPerformanceCounter这 ...