hdu1009 - 贪心
2017-07-14 18:18:31
- writer:pprp
- 介绍:hdu1009
- 题目介绍,详见hdu1009
- 代码如下
#include <iostream>
#include <algorithm>
#include <cstdio>
#include<iomanip> using namespace std; const int maxn = ; class mouse
{
public:
int j;
int f;
int divide;
}; bool cmp(mouse m1,mouse m2)
{
if(m1.divide > m2.divide)
return true;
else
return false;
} int main()
{
int m,n; mouse mou[maxn];
while(cin >> m >> n && m != - && n != -)
{
double lp = ;
for(int i = ; i < n ; i++)
{
mou[i].f = ;
mou[i].j = ;
mou[i].divide = ;
} for(int i = ; i < n ; i++)
{
cin >> mou[i].j>>mou[i].f;
mou[i].divide = mou[i].j/mou[i].f;
} sort(mou,mou+n,cmp); for(int i = ; i <n ; i++)
{
if(m >= mou[i].f)
{
m -= mou[i].f;
lp += mou[i].j; }
else
{
lp += mou[i].j*(m/(double)mou[i].f);
}
}
printf("%.3f\n",lp);
} return ;
}
hdu1009 - 贪心的更多相关文章
- HDU1009老鼠的旅行 (贪心算法)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU-1009(简单贪心)
FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the ...
- HDU1009:FatMouse' Trade(初探贪心,wait)
FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containi ...
- BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1383 Solved: 582[Submit][St ...
- HDOJ 1051. Wooden Sticks 贪心 结构体排序
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]
1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 786 Solved: 391[Submit][S ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【BZOJ-4245】OR-XOR 按位贪心
4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 486 Solved: 266[Submit][Sta ...
随机推荐
- Java 使用阿里云短信的API接口
亲们上午好,写的不好的地方还望指正.谢谢各位! 引言 短信服务(Short Message Service)是阿里云为用户提供的一种通信服务的能力,支持快速发送短信验证码.短信通知等.(我这里只讲一个 ...
- 适配器模式(Adapter Pattern)--不兼容结果的协调
定义:将一个接口转换成客户希望的另一个接口,使接口不兼容的那些类可以一起工作,其别名为包装器(Wrapper); 分类: 对象适配器:适配器与适配者之间是关联关系; 类适配器:适配器和适配者之间是继承 ...
- 剑指Offer——数组中的逆序对
题目描述: 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.输入一个数组,求出这个数组中的逆序对的总数P.并将P对1000000007取模的结果输出. 即输出P%100 ...
- type为number的<input>标签 type和size属性失效
html5中input的type属性增的可取值新增几种,对于不支持这几种新增值的浏览器会统一解析为text类型. Firefox.ie9不支持
- (转)CentOs7.3 搭建 RabbitMQ 3.6 Cluster 集群服务与使用
RabbitMQ是一个开源的AMQP实现,服务器端用Erlang语言编写,支持多种客户端,如:Python.Ruby..NET.Java.JMS.C.PHP.ActionScript.XMPP.STO ...
- Linux 最常用的20条命令
1.cd命令 这是一个非常基本,也是大家经常需要使用的命令,它用于切换当前目录,它的参数是要切换到的目录的路径,可以是绝对路径,也可以是相对路径.如: cd /root/Docements # 切 ...
- class-dump安装与使用
简介 class-dump is a command-line utility for examining the Objective-C segment of Mach-O files. It ge ...
- jquery模拟点击A标签的问题
我尝试过多次用jQuery模拟用户点击a标签的功能,但都没有成功,并且困扰了很久. 先看下边的代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <htm ...
- 如何下载java的jdk
1.https://www.oracle.com/index.html 2.https://www.oracle.com/downloads/index.html 3.https://www.orac ...
- PKU 3318 Matrix Multiplication(随机化算法||状态压缩)
题目大意:原题链接 给定三个n*n的矩阵A,B,C,验证A*B=C是否成立. 所有解法中因为只测试一组数据,因此没有使用memset清零 Hint中给的傻乎乎的TLE版本: #include<c ...