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. Spring Boot 启动的时候遇到 java.lang.ClassNotFoundException: ch.qos.logback.classic.Level

    在刚开始接触spring boot的时候,想创建一个Hello World 的project. 但是创建完之后,Run as 'Spring Boot APP'的时候遇到这个错误. Level类存在于 ...

  2. 2015 Multi-University Training Contest 3 hdu 5318 The Goddess Of The Moon

    The Goddess Of The Moon Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/ ...

  3. nutch+hadoop 配置使用

    nutch+hadoop 配置使用 配置nutch+hadoop 1,下载nutch.如果不需要特别开发hadoop,则不需要下载hadoop.因为nutch里面带了hadoop core包以及相关配 ...

  4. npm API文档

    npm API文档 https://docs.npmjs.com/

  5. Oracle数据库经常使用经典查询

    本文收集了经常使用的数据库查询.须要数据库管理员权限: 1. 查询暂时表空间使用情况 SELECT TABLESPACE_NAME, TABLESPACE_SIZE / 1024 / 1024 TAB ...

  6. Keil5.15版本号

    Keil5.15下载地址 http://pan.baidu.com/s/1kT6AGvX Keil5.15软件补丁下载地址 http://www.keil.com/dd2/pack/ Keil5.15 ...

  7. Android程序之全国天气预报查询(聚合数据开发)

    一.项目演示效果例如以下: 项目源码下载地址: http://pan.baidu.com/s/1pL6o5Mb password:5myq 二.使用 聚合数据SDK: (1)聚合数据官网地址:http ...

  8. Genymotion出现Installation error: INSTALL_FAILED_CPU_ABI_INCOMPATIBLE错误解决方法

    今天在Genymotion上执行曾经的一个项目(libs中有多个SDK和so文件)时,出现下面错误: Console控制台中:Installation error: INSTALL_FAILED_CP ...

  9. 从ORA-27300,ORA-27301到ORA-00064

        近期因为session数量添加,须要调整session,也就是要调整process參数. 看是比較简单的一个问题,却遭遇了ORA-27300,ORA-27301.因为这个涉及到了有关内核參数k ...

  10. dexposed框架Android在线热修复

    移动client应用相对于Webapp的最大一个问题每次出现bug,不能像web一样在server就完毕修复,不须要发版本号.紧急或者有安全漏洞的问题, 假设是Webapp你可能最多花个1,2个小时紧 ...