bzoj2014 [Usaco2010 Feb]Chocolate Buying
Description
巧克力品种 | 单价 | 高兴的奶牛数量 |
1 2 3 4 5 |
5 1 10 7 60 |
3 1 4 2 1 |
Input
Output
Sample Input
53
11
10 4
7 2
60 1
Sample Output
就是限制价值为1背包dp
那这样就可以用贪心搞了
#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
struct item{
LL c,p;
}a[100010];
int n;
LL m,ans,rest;
inline bool cmp(const item &a,const item &b){return a.c<b.c;}
inline LL min(LL a,LL b)
{return a<b?a:b;}
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int main()
{
n=read();m=read();
for (int i=1;i<=n;i++)
{a[i].c=read();a[i].p=read();}
sort(a+1,a+n+1,cmp);
for (int i=1;i<=n;i++)
{
LL num=min(m/a[i].c,a[i].p);
ans+=num;m-=num*a[i].c;
}
printf("%lld",ans);
}
bzoj2014 [Usaco2010 Feb]Chocolate Buying的更多相关文章
- 【BZOJ】2014: [Usaco2010 Feb]Chocolate Buying(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=2014 这应该是显然的贪心吧,先排序,然后按花费取 #include <cstdio> # ...
- [Usaco2010 Feb]Chocolate Buying
题目描述 贝西和其他奶牛们都喜欢巧克力,所以约翰准备买一些送给她们.奶牛巧克力专卖店里 有N种巧克力,每种巧克力的数量都是无限多的.每头奶牛只喜欢一种巧克力,调查显示, 有Ci头奶牛喜欢第i种 ...
- BZOJ 2015: [Usaco2010 Feb]Chocolate Giving( 最短路 )
裸最短路.. ------------------------------------------------------------------------------------ #include ...
- 2015: [Usaco2010 Feb]Chocolate Giving
2015: [Usaco2010 Feb]Chocolate Giving Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 269 Solved: 1 ...
- bzoj2015 [Usaco2010 Feb]Chocolate Giving
Description Farmer John有B头奶牛(1<=B<=25000),有N(2*B<=N<=50000)个农场,编号1-N,有M(N-1<=M<=10 ...
- 【BZOJ】2015: [Usaco2010 Feb]Chocolate Giving(spfa)
http://www.lydsy.com/JudgeOnline/problem.php?id=2015 这种水题真没啥好说的.. #include <cstdio> #include & ...
- bzoj 2015: [Usaco2010 Feb]Chocolate Giving【spfa】
因为是双向边,所以相当于两条到1的最短路和,先跑spfa然后直接处理询问即可 #include<iostream> #include<cstdio> #include<q ...
- BZOJ2016: [Usaco2010 Feb]Chocolate Eating
[传送门:BZOJ2016] 简要题意: 贝西收到了N 块巧克力,她会在接下来的D 天里吃掉这些巧克力,她想制定一个计划,让她每 天的快乐度都保持在较高的水品上. 在第一天刚开始的时候,贝西的快乐度为 ...
- BZOJ1782: [Usaco2010 Feb]slowdown 慢慢游
1782: [Usaco2010 Feb]slowdown 慢慢游 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 541 Solved: 326[Sub ...
随机推荐
- JAVA的类加载器,详细解释
JVM规范定义了两种类型的类装载器:启动内装载器(bootstrap)和用户自定义装载器(user-defined class loader). 一. ClassLoader基本概念 1.ClassL ...
- 年度钜献,108个大数据文档PDF开放下载
1.大数据的开放式创新——吴甘沙 相关阅读:[PPT]吴甘沙:让不同领域的数据真正流动.融合起来,才能释放大数据的价值 下载:大数据的开放式创新——吴甘沙.pdf 2.微软严治庆——让大数据为每个人服 ...
- 开源欣赏wordpress之intall.php
引导式安装 $weblog_title = isset( $_POST['weblog_title'] ) ? trim( wp_unslash( $_POST['weblog_title'] ) ) ...
- Min Stack 解答
Question Design a stack that supports push, pop, top, and retrieving the minimum element in constant ...
- 二十六、Jcreator使用初步
摘自http://blog.csdn.net/liujun13579/article/details/7751464 二十六.Jcreator使用初步 Jcreator是一个小巧灵活的Java开发工具 ...
- php php打乱数组二维数组、多维数组
php中的shuffle函数只能打乱一维数组,有什么办法快速便捷的打乱多维数组?手册上提供了 <?php function shuffle_assoc($list) { if (!is ...
- IOS开发之---触摸和手势
Touch:在与设备的多点触摸屏交互时生成. 响应者对象 响应者对象就是可以响应事件并对事件作出处理.在iOS中,存在UIResponder类,它定义了响应者对象的所有方法.UIApplication ...
- 安装mysql时出错。无法初始化。 libstdc++.so.5
./bin/mysqld: error while loading shared libraries: libstdc++.so.5: cannot open shared object file: ...
- 7. Shell 脚本编写
一.Shell 脚本编写 1.提示用户输入一个字符串,如果是 hello,打出 yes,并每秒输出 "hello,world",否则就输出 no,实现如下: #!/bin/bash ...
- sublimetext3官网安装
1. 下载 可以从官网 http://www.sublimetext.com/3 下载. 2. Windows下安装与使用2.1 安装 1. Win7 64位系统,可以下载 Windows 64 bi ...