洛谷—— P2983 [USACO10FEB]购买巧克力Chocolate Buying
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
输入输出样例
5 50
5 3
1 1
10 4
7 2
60 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的更多相关文章
- 洛谷——P2983 [USACO10FEB]购买巧克力Chocolate Buying
P2983 [USACO10FEB]购买巧克力Chocolate Buying 题目描述 Bessie and the herd love chocolate so Farmer John is bu ...
- 洛谷 P2983 [USACO10FEB]购买巧克力Chocolate Buying 题解
P2983 [USACO10FEB]购买巧克力Chocolate Buying 题目描述 Bessie and the herd love chocolate so Farmer John is bu ...
- 洛谷 P2983 [USACO10FEB]购买巧克力Chocolate Buying
购买巧克力Chocolate Buying 乍一看以为是背包,然后交了一个感觉没错的背包上去. #include <iostream> #include <cstdio> #i ...
- 洛谷P2983 [USACO10FEB]购买巧克力Chocolate Buying
题目描述 Bessie and the herd love chocolate so Farmer John is buying them some. The Bovine Chocolate Sto ...
- 【洛谷】P2983 [USACO10FEB]购买巧克力Chocolate Buying(贪心)
题目描述 Bessie and the herd love chocolate so Farmer John is buying them some. The Bovine Chocolate Sto ...
- P2983 [USACO10FEB]购买巧克力Chocolate Buying
题目描述 Bessie and the herd love chocolate so Farmer John is buying them some. The Bovine Chocolate Sto ...
- [USACO10FEB]购买巧克力Chocolate Buying
题目描述 Bessie and the herd love chocolate so Farmer John is buying them some. The Bovine Chocolate Sto ...
- [USACO10FEB]购买巧克力Chocolate Buying 【假背包真贪心】 By cellur925
题目传送门 继续dp刷题计划,看到这道题,第一眼感觉不就是显然的完全背包嘛.把背包打完要开始填充数组大小的时候成为了mengbier,发现数据极大,达到了1e18.显然这不是一道平凡的背包题目. 于是 ...
- 洛谷 P2984 [USACO10FEB]给巧克力Chocolate Giving
题目描述 Farmer John is distributing chocolates at the barn for Valentine's day, and B (1 <= B <= ...
随机推荐
- [NOIP2012提高组]开车旅行
题目:洛谷P1081.Vijos P1780.codevs1199. 题目大意:有n座海拔高度不相同的城市(编号1~n),两城市的距离就是两城市海拔之差.规定每次只能从编号小的城市走到编号大的城市. ...
- CF1037E Trips (离线+图上构造)
题目大意:一共有n个人,每天早上会有两个人成为朋友,朋友关系不具有传递性,晚上,它们会组织旅游,如果一个人去旅游,那么他不少于$k$个朋友也要和他去旅游,求每天的最大旅游人数 一开始并没有想到反向建图 ...
- webpack中关于require与import的区别
1.require常见使用场景: var path = require('path') var utils = require('./utils') 此时webpack会将path/utils/con ...
- python_元组、字典
1.元组无法修改,只能索引2.只有两种方法 count 和 indexnames = ("Alex","jack")print(names.count(&quo ...
- sql学习笔记(18)-----------数据库创建过程
手动创建数据库的步骤: 第一步:决定数据库实例的SID 数据库实例的SID用来将当前实例和以后可能创建的实例进行区分 % setenv ORACLE_SID mynewdb 第二步:建立数 ...
- 今天修了一个bug,关于debug日志的问题
是别人的代码,很诡异. 就是开了debug日志,没问题. 关了debug日志,就出问题. 开始我以为是debug日志拖慢了速度,所以有一些竞态环境的影响. 后来发现是在debug日志里面有一些side ...
- HDU 4312 Contest 2
题目要求两点间的最大值作为距离即: 即是切比雪夫距离.而切比雪夫距离与曼哈顿距离的转换却很巧妙. 把平面坐标所有点绕原点逆向旋转45度后,所得点的曼哈顿距离之和除以√2,即是切雪比夫距离.旋转点的公式 ...
- Android ToolBar 的简单封装
使用过 ToolBar 的朋友肯定对其使用方法不陌生,由于其使用方法非常easy.假设对 ActionBar 使用比較熟练的人来说.ToolBar 就更easy了!只是,相信大家在使用的过程中都遇到过 ...
- 【Linux驱动】TQ2440 DM9000E网卡驱动移植(Linux-2.6.30.4)
花了一天的时间研究了一下Linux-2.6.30.4版本号内核下关于TQ2440 DM9000E的网卡驱动移植.总结一下自己的收获. 事实上.在Linux-2.6.30.4版本号内核下有关于网卡驱动, ...
- Win10使用VMware虚拟机安装ubuntu
Win10专业版自带有虚拟机安装工具Hyper-V,也可以使用其他如VMware工具安装,也挺方便. 所需工具: 1. VMware-workstation 下载链接: http://rj.bai ...