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 ...
随机推荐
- 四款超棒的jQuery数字化签名插件
在浏览器中,我们有很多方式来绘制生成签名效果,并且有很多很棒很智能的jQuery插件.数字化签名是未来的发展方向,正是这个原因我们这里收集并且推荐了四款超棒的jQuery数字化签名插件,希望大家喜欢! ...
- C++第一章概述
1:C++主要是对于C的继承性做的相当的出色,主要扩充在于程序员可以自己定义自己的数据结构,用数据结构去描述日常生活中的事务,而不是C语言中当当仅有的Struct数据类型等等 2: 每一种语言都有自己 ...
- LeetCode题解——Longest Common Prefix
题目: 给定一系列的字符串,找出这些字符串的最长公共前缀. 解法: 暴力法,依次比较每个字符串的每个字符,碰到第一个不同的就返回之前找到的前缀. 代码: class Solution { public ...
- sf空间配置
1.创建VHost 记住Homepage,打开VHost DNS标签页,创建Virtual Host,如下图: 2.Wcp上传文件 用户名是"sf用户名,sf项目名" ...
- linux查看端口信息以及关闭进程
lsof -i:6633 查看端口6633的使用情况 kill (+PID数值),结束进程
- JAVA使用jdbc连接MYSQL简单示例
以下展示的为JAVA使用jdbc连接MYSQL简单示例: import java.sql.DriverManager; import java.sql.ResultSet; import java.s ...
- Web Service学习之九:Restful WebService
1.Rest 2.Rest webService 3.SpringMVC Restful 参考: http://spring.io/guides/gs/rest-service/ http://www ...
- Java邮件服务学习之二:SMTP和POP3
一.SMTP SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则.SMTP协议属于TCP/IP协议簇,它帮助每台计算 ...
- 给 TTreeView 添加复选框
//1.引用单元 uses Commctrl ; //2.定义私有过程 procedure tvToggleCheckbox(TreeView: TTreeView;Node: TTreeNode;i ...
- 基于 Red5 的流媒体服务器的搭建和应用
http://www.ibm.com/developerworks/cn/opensource/os-cn-Red5/ Red5 是一个采用 Java 开发的开源免费 Flash 流媒体服务器.Red ...