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

    贝西和其他奶牛们都喜欢巧克力,所以约翰准备买一些送给她们。奶牛巧克力专卖店里
有N种巧克力,每种巧克力的数量都是无限多的。每头奶牛只喜欢一种巧克力,调查显示,
有Ci头奶牛喜欢第i种巧克力,这种巧克力的售价是P。
    约翰手上有B元预算,怎样用这些钱让尽量多的奶牛高兴呢?下面举个例子:假设约翰
有50元钱,商店里有S种巧克力:
  巧克力品种
    单价
    1
    2
    3
    4
    5
    5
    1
    10
    7
    60
    3
    1
    4
    2
    1
 
 
 
    显然约翰不会去买第五种巧克力,因为他钱不够,不过即使它降价到50,也不该选择
它,因为这样只会让一头奶牛高兴,实在太浪费了。最好的买法是:第二种买1块,第一种
买3块,第四种买2块,第三种买2块,正好用完50元,可以让1+3+2+2=8头牛高兴。

Input

  第一行:两个用空格分开的整数:N和B,1<=N≤100000,1≤B≤10^18
  第二行到N+1行:第i+l行,是两个用空格分开的整数:Pj和Ci,1≤Pi,Ci≤10^18

Output

  第一行:一个整数,表示最多可以让几头奶牛高兴

Sample Input

5 50
53
11
10 4
7 2
60 1

Sample Output

8

HINT

Source

【BZOJ】2014: [Usaco2010 Feb]Chocolate Buying(贪心)的更多相关文章

  1. BZOJ 2015: [Usaco2010 Feb]Chocolate Giving( 最短路 )

    裸最短路.. ------------------------------------------------------------------------------------ #include ...

  2. bzoj2014 [Usaco2010 Feb]Chocolate Buying

    Description     贝西和其他奶牛们都喜欢巧克力,所以约翰准备买一些送给她们.奶牛巧克力专卖店里 有N种巧克力,每种巧克力的数量都是无限多的.每头奶牛只喜欢一种巧克力,调查显示, 有Ci头 ...

  3. [Usaco2010 Feb]Chocolate Buying

    题目描述     贝西和其他奶牛们都喜欢巧克力,所以约翰准备买一些送给她们.奶牛巧克力专卖店里 有N种巧克力,每种巧克力的数量都是无限多的.每头奶牛只喜欢一种巧克力,调查显示, 有Ci头奶牛喜欢第i种 ...

  4. bzoj 2015: [Usaco2010 Feb]Chocolate Giving【spfa】

    因为是双向边,所以相当于两条到1的最短路和,先跑spfa然后直接处理询问即可 #include<iostream> #include<cstdio> #include<q ...

  5. 2015: [Usaco2010 Feb]Chocolate Giving

    2015: [Usaco2010 Feb]Chocolate Giving Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 269  Solved: 1 ...

  6. [bzoj 1782] [Usaco2010 Feb]slowdown慢慢游

    [bzoj 1782] [Usaco2010 Feb]slowdown慢慢游 Description 每天Farmer John的N头奶牛(1 <= N <= 100000,编号1-N)从 ...

  7. BZOJ 1782: [Usaco2010 Feb]slowdown 慢慢游( BIT + dfs )

    orz...hzwer 对着大神的 code 看 , 稍微理解了. 考虑一只牛到达 , 那它所在子树全部 +1 , 可以用BIT维护 --------------------------------- ...

  8. 【BZOJ】2015: [Usaco2010 Feb]Chocolate Giving(spfa)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2015 这种水题真没啥好说的.. #include <cstdio> #include & ...

  9. bzoj2015 [Usaco2010 Feb]Chocolate Giving

    Description Farmer John有B头奶牛(1<=B<=25000),有N(2*B<=N<=50000)个农场,编号1-N,有M(N-1<=M<=10 ...

随机推荐

  1. JMeter 一:Elements of a Test Plan

    参考:http://jmeter.apache.org/usermanual/test_plan.html 最小测试集包括:Test Plan,一个Thread Group,以及一个或多个Sample ...

  2. 2014小米,百度,pptv,去哪儿笔试题目回忆

    今天一共笔试了这四家,真累啊,上午10点小米,下午2点百度,下午3点PPTV,下午5点去哪儿,今天右手太酸了,打的都话了50左右,如果没面试通知,那我可亏大了 小米就三题: 1.一个数组,排序要求,所 ...

  3. 【MVC5】日期选择控件DatePicker

    项目中使用了Bootstrap,日期控件就选择了依赖于bootstrap的DatePicker. 在App_Start\BundleConfig.cs中引用css和js文件: bundles.Add( ...

  4. bootstrap的两种在input框里面增加一个图标的方式

    具体代码如下: <div class="input-group"> <div class="input-icon-group"> < ...

  5. mac 安装2个xcode 时会导致找不到xcodebuild

    mac 安装2个xcode 时会导致找不到xcodebuild 解决方案: sudo  xcode-select --switch /Applications/Xcode.app/Contents/D ...

  6. Android中的倒计时实现

    一.android.os包下提供了倒计时的抽象工具类: public abstract class CountDownTimer { /** * Millis since epoch when ala ...

  7. Ubuntu11.04中如何将pycharm添加到系统的“应用程序”菜单里 (pycharm已成功安装)

    默认排序 Stu.zhouyc   21 人赞同了该回答 tools---->create desktop entry...不是很方便吗? 发布于 2016-04-09 21添加评论 分享 收藏 ...

  8. 什么是SQL注入式攻击?

    什么是SQL注入式攻击? 所谓SQL注入式攻击,就是攻击者把SQL命令插入到Web表单的输入域或页面请求的查询字符串,欺骗服务器执行恶意的SQL命令.在某些表单中,用户输入的内容直接用来构造(或者影响 ...

  9. 分布式协调服务ZooKeeper工作原理

    分布式协调服务ZooKeeper工作原理 原创 2016-02-19 杜亦舒 性能与架构 性能与架构 性能与架构 微信号 yogoup 功能介绍 网站性能提升与架构设计 大数据处理框架Hadoop.R ...

  10. python得到今天前的七天每天日期

    import datetime d = datetime.datetime.now() def day_get(d): # 通过for 循环得到天数,如果想得到两周的时间,只需要把8改成15就可以了. ...