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 ...
随机推荐
- SIM卡尺寸及剪卡教程
手机SIM卡有全尺寸SIM卡.Mini-SIM卡.Micro-SIM卡.Nano-SIM卡.Embedded-SIM卡等类型,目前主流手机基本都是趋向使用Micro-SIM卡和Nano-SM卡. 一. ...
- UESTC_温泉旅店 CDOJ 878
天空飘下一朵一朵的雪花,这是一片纯白的世界. 在天空之下的温泉旅店里,雪菜已醉倒在一旁,冬马与春希看了看说着梦话的雪菜,决定找一点玩的来度过这愉快的晚上. 这家旅店提供一种特色游戏,游戏有n张牌,各写 ...
- execute immediate的简单用法(oracle)
直接上示例代码: create or replace procedure proc_test( --参数区域 ) is --变量区域 --sql脚本 v_sql ) :=''; --记录学生数量 v_ ...
- Back to Underworld(搜索)
Back to Underworld Time Limit:4000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Su ...
- 3第一周课后练习·阅读计划(3)-使用函数来访问私有数据成员
/* * Copyright (c) 2015, 计算机科学学院,烟台大学 * All rights reserved. * 文件名:test.cpp * 作 靠:刘畅 * 完成日期:2015年 3 ...
- SQL SERVER 2005 请求失败或服务未及时响应
出现的问题如图所示,在开始->程序->Microsoft SQL Server 2005->配置工具->SQL Server Configuration Manager中,打开 ...
- DWZ在APS.NET WebForm中的使用(二)
任何框架由于个人理解不到位或者框架自身的局限性,在项目实施中,大家或多或少都会遇到一些问题,下面我就讲述下我在使用DWZ开发过程中的几个问题.如有一点能帮助到你,这篇文章也算有存在的意义了. 1.树菜 ...
- 清理SQL数据库日志
Use DBSelect NAME,size From sys.database_files ALTER DATABASE DB SET RECOVERY SIMPLE WITH NO_WAIT AL ...
- 使用SQLCipher加密数据库
Xcode中集成了免费的sqlite,但是不提供加密的模块,突然有一天,蛋疼的客户要求把数据进行加密,于是乎就寻找使用简单并且可以把数据迁移过度到加密数据库的框架. SQLCipher是第三方的开 ...
- Java转换
1.如何将字符串String转化为整数int int i = Integer.parseInt(str); int i = Integer.valueOf(my_str).intValue(); ...