https://www.luogu.org/problem/show?pid=2983

题目描述

Bessie and the herd love chocolate so Farmer John is buying them some.

The Bovine Chocolate Store features N (1 <= N <= 100,000) kinds of chocolate in essentially unlimited quantities. Each type i of chocolate has price P_i (1 <= P_i <= 10^18) per piece and there are C_i (1 <= C_i <= 10^18) cows that want that type of chocolate.

Farmer John has a budget of B (1 <= B <= 10^18) that he can spend on chocolates for the cows. What is the maximum number of cows that he can satisfy? All cows only want one type of chocolate, and will be satisfied only by that type.

Consider an example where FJ has 50 to spend on 5 different types of chocolate. A total of eleven cows have various chocolate preferences:

Chocolate_Type Per_Chocolate_Cost Cows_preferring_this_type 1 5 3

2 1 1

3 10 4

4 7 2

5 60 1

Obviously, FJ can't purchase chocolate type 5, since he doesn't have enough money. Even if it cost only 50, it's a counterproductive purchase since only one cow would be satisfied.

Looking at the chocolates start at the less expensive ones, he can purchase 1 chocolate of type #2 for 1 x 1 leaving 50- 1=49, then purchase 3 chocolate of type #1 for 3 x 5 leaving 49-15=34, then purchase 2 chocolate of type #4 for 2 x 7 leaving 34-14=20, then purchase 2 chocolate of type #3 for 2 x 10 leaving 20-20= 0.

He would thus satisfy 1 + 3 + 2 + 2 = 8 cows.

贝西和其他奶牛们都喜欢巧克力,所以约翰准备买一些送给她们。奶牛巧克力专卖店里

有N种巧克力,每种巧克力的数量都是无限多的。每头奶牛只喜欢一种巧克力,调查显示,

有Ci头奶牛喜欢第i种巧克力,这种巧克力的售价是P。

约翰手上有B元预算,怎样用这些钱让尽量多的奶牛高兴呢?

输入输出格式

输入格式:

  • Line 1: Two space separated integers: N and B

  • Lines 2..N+1: Line i contains two space separated integers defining chocolate type i: P_i and C_i

输出格式:

  • Line 1: A single integer that is the maximum number of cows that Farmer John can satisfy

输入输出样例

输入样例#1:

5 50
5 3
1 1
10 4
7 2
60 1
输出样例#1:

8
 #include <algorithm>
#include <cstdio> using namespace std; long long n,B,sum,ans;
struct Node
{
long long pri,cnt;
bool operator < (const Node &x) const
{
if(pri==x.pri) return cnt>x.cnt;
return pri<x.pri;
}
}cow[]; int main()
{
scanf("%lld%lld",&n,&B);
for(int i=;i<=n;i++)
scanf("%lld%lld",&cow[i].pri,&cow[i].cnt);
sort(cow+,cow+n+);
for(long long i=;i<=n;i++)
{
long long tmp=B/cow[i].pri;
if(tmp>cow[i].cnt)
ans+=cow[i].cnt,B-=cow[i].cnt*cow[i].pri;
else
{
ans+=tmp;
break;
}
}
printf("%lld\n",ans);
return ;
}

洛谷—— P2983 [USACO10FEB]购买巧克力Chocolate Buying的更多相关文章

  1. 洛谷——P2983 [USACO10FEB]购买巧克力Chocolate Buying

    P2983 [USACO10FEB]购买巧克力Chocolate Buying 题目描述 Bessie and the herd love chocolate so Farmer John is bu ...

  2. 洛谷 P2983 [USACO10FEB]购买巧克力Chocolate Buying 题解

    P2983 [USACO10FEB]购买巧克力Chocolate Buying 题目描述 Bessie and the herd love chocolate so Farmer John is bu ...

  3. 洛谷 P2983 [USACO10FEB]购买巧克力Chocolate Buying

    购买巧克力Chocolate Buying 乍一看以为是背包,然后交了一个感觉没错的背包上去. #include <iostream> #include <cstdio> #i ...

  4. 洛谷P2983 [USACO10FEB]购买巧克力Chocolate Buying

    题目描述 Bessie and the herd love chocolate so Farmer John is buying them some. The Bovine Chocolate Sto ...

  5. 【洛谷】P2983 [USACO10FEB]购买巧克力Chocolate Buying(贪心)

    题目描述 Bessie and the herd love chocolate so Farmer John is buying them some. The Bovine Chocolate Sto ...

  6. P2983 [USACO10FEB]购买巧克力Chocolate Buying

    题目描述 Bessie and the herd love chocolate so Farmer John is buying them some. The Bovine Chocolate Sto ...

  7. [USACO10FEB]购买巧克力Chocolate Buying

    题目描述 Bessie and the herd love chocolate so Farmer John is buying them some. The Bovine Chocolate Sto ...

  8. [USACO10FEB]购买巧克力Chocolate Buying 【假背包真贪心】 By cellur925

    题目传送门 继续dp刷题计划,看到这道题,第一眼感觉不就是显然的完全背包嘛.把背包打完要开始填充数组大小的时候成为了mengbier,发现数据极大,达到了1e18.显然这不是一道平凡的背包题目. 于是 ...

  9. 洛谷 P2984 [USACO10FEB]给巧克力Chocolate Giving

    题目描述 Farmer John is distributing chocolates at the barn for Valentine's day, and B (1 <= B <= ...

随机推荐

  1. python生成器,递归调用

    生成器 什么是生成器:只要在函数体内出现yield关键字,那么再执行函数就不会执行函数代码,会得到一个结果,该结果就是生成器 生成器就是迭代器 yield的功能 yield为我们提供了一种自定义迭代器 ...

  2. 实战:vue项目中导入swiper插件

    版本选择 swiper是个常用的插件,现在已经迭代到了第四代:swiper4.常用的版本是swiper3和swiper4,我选择的是swiper3. 安装 安装swiper3的最新版本3.4.2: n ...

  3. JS 一个简单的隔行变色函数

    //输入要隔行变色的标签名 function setbgColor(tr){ var tr = document.getElementsByTagName("tr"); for(v ...

  4. linux gnome kde点滴

    2014.12.08 下面切换的方法对于fedora 17没有效果,对于fedora 17, 要使用system-switch-displaymanager,出现 点击相应的选项,然后就进入相应的启动 ...

  5. Hive分区表与分桶

    分区表 在Hive Select查询中.通常会扫描整个表内容,会消耗非常多时间做不是必需的工作. 分区表指的是在创建表时,指定partition的分区空间. 分区语法 create table tab ...

  6. bzoj4547: Hdu5171 小奇的集合(矩阵乘法)

    4547: Hdu5171 小奇的集合 题目:传送门 题解: 做一波大佬们的坑...ORZ 不得不说,我觉得矩阵很简单啊,就一个3*3的(直接看代码吧) 给个递推柿纸:f[i]=f[i-1]+max1 ...

  7. [JZOJ NOIP2018模拟10.21]

    考试之前我刚刚领略到了特判的重要性,没想到T2的两个子任务还是写挂了,丢了20分 考试的感觉不行,一路打的都是暴力,正解的思路想到一半就断了推不下去 T1:逛公园 题目链接: https://jzoj ...

  8. 字符串转换整数 (atoi) C++实现 java实现 leetcode系列(八)

    字符串转换整数 (atoi) java实现 C++实现 请你来实现一个 atoi 函数,使其能将字符串转换成整数. 首先,该函数会根据需要丢弃无用的开头空格字符,直到寻找到第一个非空格的字符为止. 当 ...

  9. 你不知道的JavaScript(一)数据类型

    ECMAScript 规范地址: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf 有过WEB前端开发 ...

  10. lua-C++ userdata使用

    lua-C++ userdata使用 所负责的产品使用非常灵活,可设置的参数上千个,而且还支持用户用lua进行流程控制,所以开发中要用到很多lua.C++混合编程.之前对这些也还是一知半解,只会依葫芦 ...