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 ...
随机推荐
- Yii框架2.0的过滤器
过滤器是 控制器 动作 执行之前或之后执行的对象. 例如访问控制过滤器可在动作执行之前来控制特殊终端用户是否有权限执行动作, 内容压缩过滤器可在动作执行之后发给终端用户之前压缩响应内容. 过滤器可包含 ...
- requests和bs4
requests模块,仿造浏览器发送Http请求bs4主要对html或xml格式字符串解析成对象,使用find/find_all查找 text/attrs 爬取汽车之家 爬取汽车之家的资讯信息,它没有 ...
- What’s wrong with virtual methods called through an interface
May 31, 2016 Calling a virtual method through an interface always was a lot slower than calling a st ...
- IPython的基本功能(转)
原文:http://kochiya.me/www/posts/Ipython!.html 前几天偶然在公司内网上拖了一本 Learning IPython for Interactive Comput ...
- 《iOS Human Interface Guidelines》——Popover
弹出框 弹出框是当人们点击一个控件或屏幕上一个区域时显示的一个暂时的界面. API NOTE 在iOS 8及以后的系统中.你能够使用UIPopoverPresentationController来显示 ...
- thread msg
提取的nordic rf51xx/rf52xx sdk中的线程间消息通信机制,非常简洁 demo.c #include <stdio.h> #include <stdlib.h> ...
- 我的第一次NGS分析操作
部分参考自:生物信息学100个基础问题 —— 番外2: 用Anaconda快速搭建生物信息学分析平台 - 孟浩巍的文章 - 知乎 https://zhuanlan.zhihu.com/p/357114 ...
- lua全局状态机
本文内容基于版本:Lua 5.3.0 global_State概述 global_State结构,我们可以称之为Lua全局状态机.从Lua的使用者角度来看,global_State结构是完全感知不到的 ...
- HDU - 4871 Shortest-path tree (最短路径树+ 树分治)
题意:给你一张带权无向图,先求出这张图从点1出发的最短路树,再求在树上经过k个节点最长的路径值,以及个数. 分析:首先求最短路树,跑一遍最短路之后dfs一遍即可建出最短路树. 第二个问题,树分治解决. ...
- 【java】使用Builder模式,轻松应对动态繁杂的方法参数
背景:在咱编写的图片处理模块里,针对加载这个方法,参数很多,如: /** * 加载图片,经过内存.磁盘.两层缓存如果还没找到,则走http访问网络资源 * @param url 地址 * @param ...