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. C# 5 in a Nutshell - Delegate

    1. What is delegate in C#? A delegate is an object that knows how to call a method.A delegate type d ...

  2. POI-word转html

    package com.test.poiword; import android.app.Activity; import android.os.Bundle; import android.webk ...

  3. Hacker - 世界上第一个黑客

    http://juliet.iteye.com/blog/176525凯文·米特尼克,1964年生于美国加州的洛杉矶. 13岁时他对电脑着了迷,掌握了丰富的计算机知识和高超的操作技能,但却因为用学校的 ...

  4. Shell编程二

    告警系统需求分析 1.(虽然之前我们学习了zabbix,但有时候也不能满足我们的需求,比如比较冷门的监控项目需要写自定义脚本,或者服务器网络有问题,没有办法将客户端的数据发送到服务端.) 程序架构: ...

  5. Linux - 进程控制 代码(C)

    进程控制 代码(C) 本文地址:http://blog.csdn.net/caroline_wendy 输出进程ID.getpid(). 代码: /*By C.L.Wang * Eclipse CDT ...

  6. Python 实现字符串转换成列表 实现str转换list

    其中Python strip() 方法用于移除字符串头尾指定的字符 split()就是将一个字符串分裂成多个字符串组成的列表 >>> image ='1.jsp,2.jsp,3.js ...

  7. Java小型知识点

    1. API 1.1 byte[].File.InputStream 互相转换 1.将File.FileInputStream 转换为byte数组: File file = new File(&quo ...

  8. ZOJ 3703 Happy Programming Contest(0-1背包)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3703 Happy Programming Contest Time Lim ...

  9. iOS开发多线程篇 08 —GCD的常见用法

    iOS开发多线程篇—GCD的常见用法 一.延迟执行 1.介绍 iOS常见的延时执行有2种方式 (1)调用NSObject的方法 [self performSelector:@selector(run) ...

  10. ubuntu 安装python3.5

    wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz xz -d Python-.tar.xz .tar cd Python ...