【BZOJ】2014: [Usaco2010 Feb]Chocolate Buying(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=2014
这应该是显然的贪心吧,先排序,然后按花费取
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%lld", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr2(a, b, c) for1(i, 1, b) { for1(j, 1, c) cout << a[i][j]; cout << endl; }
#define printarr1(a, b) for1(i, 1, b) cout << a[i]; cout << endl
typedef long long ll;
inline const ll getint() { ll r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const ll min(const ll &a, const ll &b) { return a<b?a:b; } const int N=100005;
struct dat { ll c, w; }a[N];
bool cmp(const dat &a, const dat &b) { return a.c<b.c; }
ll V, ans; int n; int main() {
read(n); read(V);
for1(i, 1, n) read(a[i].c), read(a[i].w);
sort(a+1, a+1+n, cmp);
for1(i, 1, n) {
if(V<a[i].c) break;
ll t=V/a[i].c;
t=min(t, a[i].w);
ans+=t;
V-=a[i].c*t;
}
print(ans);
return 0;
}
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
HINT
Source
【BZOJ】2014: [Usaco2010 Feb]Chocolate Buying(贪心)的更多相关文章
- BZOJ 2015: [Usaco2010 Feb]Chocolate Giving( 最短路 )
裸最短路.. ------------------------------------------------------------------------------------ #include ...
- bzoj2014 [Usaco2010 Feb]Chocolate Buying
Description 贝西和其他奶牛们都喜欢巧克力,所以约翰准备买一些送给她们.奶牛巧克力专卖店里 有N种巧克力,每种巧克力的数量都是无限多的.每头奶牛只喜欢一种巧克力,调查显示, 有Ci头 ...
- [Usaco2010 Feb]Chocolate Buying
题目描述 贝西和其他奶牛们都喜欢巧克力,所以约翰准备买一些送给她们.奶牛巧克力专卖店里 有N种巧克力,每种巧克力的数量都是无限多的.每头奶牛只喜欢一种巧克力,调查显示, 有Ci头奶牛喜欢第i种 ...
- bzoj 2015: [Usaco2010 Feb]Chocolate Giving【spfa】
因为是双向边,所以相当于两条到1的最短路和,先跑spfa然后直接处理询问即可 #include<iostream> #include<cstdio> #include<q ...
- 2015: [Usaco2010 Feb]Chocolate Giving
2015: [Usaco2010 Feb]Chocolate Giving Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 269 Solved: 1 ...
- [bzoj 1782] [Usaco2010 Feb]slowdown慢慢游
[bzoj 1782] [Usaco2010 Feb]slowdown慢慢游 Description 每天Farmer John的N头奶牛(1 <= N <= 100000,编号1-N)从 ...
- BZOJ 1782: [Usaco2010 Feb]slowdown 慢慢游( BIT + dfs )
orz...hzwer 对着大神的 code 看 , 稍微理解了. 考虑一只牛到达 , 那它所在子树全部 +1 , 可以用BIT维护 --------------------------------- ...
- 【BZOJ】2015: [Usaco2010 Feb]Chocolate Giving(spfa)
http://www.lydsy.com/JudgeOnline/problem.php?id=2015 这种水题真没啥好说的.. #include <cstdio> #include & ...
- bzoj2015 [Usaco2010 Feb]Chocolate Giving
Description Farmer John有B头奶牛(1<=B<=25000),有N(2*B<=N<=50000)个农场,编号1-N,有M(N-1<=M<=10 ...
随机推荐
- postgresql 如何导入sql文件
(1)不能使用pgadmin 执行Copy语句,目前客户端还不支持这种写法. (2)打开sql shell,执行如下操作 \i C:/Users/Peter_Youny/Desktop/ischool ...
- python gevent使用例子
python gevent使用例子 from gevent.pool import Pool POOL_SIZE = 100 def process(func, param1_list, param2 ...
- python中,== 与 is 之间区别
在python中,== 与 is 之间既有区别,又有联系,本文将通过实际代码的演示,力争能够帮助读到这篇文章的朋友以最短的时间理清二者的关系,并深刻理解它们在内存中的实现机制. 扯淡的话不多说,下面马 ...
- OpenCV中的矩阵和图像类型
任务刚刚做完,就迫不及待的来写写在OpenCV中常见的几类数据类型: 在使用OpenCV时我们时常会碰到IplImage这个数据类型,IplImage就是我们通常说的“图像”进行编码的基本结构,这些图 ...
- Firefly 流程架构
print '----startmaster------' 1print '----appmain------' 2 print '----netserver------' 3 print '---- ...
- Linux命令-网络命令:last
last 统计linux系统所有用户的登录时间(多次登录信息)
- 安装Windows Service总是发生异常!
打开VS2010 创建个windows服务应用程序!没有添加删除任何一行代码!然后按照下面的步骤 1. 将这个服务程序切换到设计视图2. 右击设计视图选择“添加安装程序”3. 切换到刚被添加的Proj ...
- Android与JS进行交互传文件路径
webview+h5这种混合开发最近很火,其中最重要的大概就是java代码和js的交互了,刚接触这东西两天,写写收获. 新建一个assets文件夹,要与res这个文件夹同级,其中存放web项目. 先看 ...
- hdu2647(拓扑排序)
链接:点击打开链接 题意:每一个人的基本工资为888,给出两个人的关系a,b,代表a的工资比b高问满足全部条件的话,最少须要支付多少钱 代码: #include <map> #includ ...
- unity, trail renderer gone black on iOS
给物体加了个trail renderer,使用了Legacy Shaders/Transparent/Diffuse,并将颜色调成白色半透明.在编辑器里效果是对的,但在ios上真机测试变成黑色的.然后 ...