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
 1 #include <algorithm>
 2 #include <cstdio>
 3
 4 using namespace std;
 5
 6 long long n,B,sum,ans;
 7 struct Node
 8 {
 9     long long pri,cnt;
10     bool operator < (const Node &x) const
11     {
12         if(pri==x.pri) return cnt>x.cnt;
13         return pri<x.pri;
14     }
15 }cow[100005];
16
17 int main()
18 {
19     scanf("%lld%lld",&n,&B);
20     for(int i=1;i<=n;i++)
21         scanf("%lld%lld",&cow[i].pri,&cow[i].cnt);
22     sort(cow+1,cow+n+1);
23     for(long long i=1;i<=n;i++)
24     {
25         long long tmp=B/cow[i].pri;
26         if(tmp>cow[i].cnt)
27             ans+=cow[i].cnt,B-=cow[i].cnt*cow[i].pri;
28         else
29         {
30             ans+=tmp;
31             break;
32         }
33     }
34     printf("%lld\n",ans);
35     return 0;
36 }

转载于:https://www.cnblogs.com/Shy-key/p/7429250.html

洛谷—— P2983 [USACO10FEB]购买巧克力Chocolate Buying相关推荐

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

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

  2. 洛谷 P2616 [USACO10JAN]购买饲料II Buying Feed, II

    P2616 [USACO10JAN]购买饲料II Buying Feed, II 题目描述 Farmer John needs to travel to town to pick up K (1 &l ...

  3. 洛谷P1108 低价购买[DP | LIS方案数]

    题目描述 "低价购买"这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:"低价购买:再低价购买".每次你购买一支股 ...

  4. 动态规划入门 洛谷P1108 低价购买

    P1108 低价购买 题目描述 "低价购买"这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:"低价购买:再低价购买&quo ...

  5. 洛谷1108低价购买

    题目描述 "低价购买"这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:"低价购买:再低价购买".每次你购买一支股 ...

  6. 低价购买(洛谷 1108)

    低价购买(洛谷 1108) 题目描述 "低价购买"这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:"低价购买:再低价购买& ...

  7. 信息学奥赛一本通 1844:【06NOIP提高组】金明的预算方案 | 洛谷 P1064 [NOIP2006 提高组] 金明的预算方案

    [题目链接] ybt 1844:[06NOIP提高组]金明的预算方案 洛谷 P1064 [NOIP2006 提高组] 金明的预算方案 [题目考点] 1. 动态规划:分组背包 2. 动态规划:依赖背包 ...

  8. 二分答案——yyy2015c01 的 U 盘(洛谷 P2370)

    题目选自洛谷P2370 两种解法,01背包+排序,或是直接二分即可 写了二分最后只有40的分...刚好过了给的四个样例 哭辽~想了半天不知道哪里错了 题目背景 在 2020 年的某一天,我们的 yyy ...

  9. 洛谷P1991 无线通讯网

    P1991 无线通讯网 170通过 539提交 题目提供者洛谷OnlineJudge 标签图论 难度普及+/提高 提交该题 讨论 题解 记录 最新讨论 怎么又炸了 为啥一直40!求解! UKE:inv ...

最新文章

  1. Junit测试JAVA文件,java – Junit测试模拟文件操作
  2. 苹果手机java_iphone手机,苹果手机如何登陆网易163邮箱
  3. struts2.2.1关于sitemesh和freemarker整合的细节
  4. 18.fields_capabilities_api
  5. 跟我学 Java 8 新特性之 Stream 流(二)关键知识点
  6. 关于Asp.Net开发中导入外部JavaScript文件的问题
  7. 重磅! flutter视图局部更新
  8. mysql的binlog意义_带你解析MySQL binlog
  9. 管能做暖气管道吗_地暖这么好,为什么大家都选暖气片?原因在于它的“隐性”成本...
  10. 201521123026《Java程序设计》第2周学习总结
  11. Unity3D脚本语言的类型系统
  12. mega linux教程,MegaRAID Storage Manager (MSM)安装使用教程
  13. Linux登录公开ftp命令,linux下登录ftp, lftp命令详解
  14. win10五分钟自动锁屏
  15. 翻译pdf中的英文 python_看不懂pdf中的英文?就用Python
  16. rip的metric策略
  17. 如何实现通过本地远程来连接OpenStack中的windows虚机
  18. 4月日本旅游签证简化办理攻略分享
  19. KCL v0.4.4 发布 - 自定义 YAML Manifests 输出以及 Python SDK
  20. 想成为牛逼网页设计师吗?

热门文章

  1. greenplum安装(单机环境)
  2. 伟大的数学家、思想家哥德尔(Hurt Godel)去世35周年
  3. 从plugin路径中读取依赖并构造对象——Azkaban源码解读之Alert plugin实现(一)
  4. 海格里斯堆垛机的安全措施 具有自我诊断的高效率堆垛机
  5. “顾磊,我想辞职!”
  6. VMware17虚拟机Linux安装教程(详解附图,带VMware Workstation 17 Pro安装)
  7. 计算机英语中translate译为,translate是什么意思_translate的翻译_音标_读音_用法_例句_爱词霸在线词典...
  8. arcTo画弧线方法
  9. mysql学习笔记---mysql的安装--rpm安装
  10. uniapp卡片式轮播图