[luoguP2983] [USACO10FEB]购买巧克力Chocolate Buying(贪心)
按价格排序后贪心
——代码
#include <cstdio>
#include <iostream>
#include <algorithm> int n;
long long m, ans;
struct node
{
long long x, y;
}p[]; inline long long read()
{
long long x = , f = ;
char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -;
for(; isdigit(ch); ch = getchar()) x = (x << ) + (x << ) + ch - '';
return x * f;
} inline bool cmp(node x, node y)
{
return x.x < y.x;
} int main()
{
int i;
long long k;
n = read();
m = read();
for(i = ; i <= n; i++) p[i].x = read(), p[i].y = read();
std::sort(p + , p + n + , cmp);
for(i = ; i <= n; i++)
{
k = m / p[i].x;
if(k > p[i].y)
{
m -= p[i].x * p[i].y;
ans += p[i].y;
}
else
{
ans += k;
break;
}
}
printf("%lld\n", ans);
return ;
}
[luoguP2983] [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 ...
- [USACO10FEB]购买巧克力Chocolate Buying 【假背包真贪心】 By cellur925
题目传送门 继续dp刷题计划,看到这道题,第一眼感觉不就是显然的完全背包嘛.把背包打完要开始填充数组大小的时候成为了mengbier,发现数据极大,达到了1e18.显然这不是一道平凡的背包题目. 于是 ...
- 洛谷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 ...
- 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
https://www.luogu.org/problem/show?pid=2983 题目描述 Bessie and the herd love chocolate so Farmer John i ...
随机推荐
- 【题解】二逼平衡树 [P3380] [BZOJ3196] [Tyvj1730]
[题解]二逼平衡树 [P3380] [BZOJ3196] [Tyvj1730] 传送门:[模板]二逼平衡树(树套树)\([P3380]\) \([BZOJ3196]\) \([TYVJ1730]\) ...
- $CF1153A\ Serval\ and\ Bus$
看大佬的代码都好复杂(不愧是大佬\(orz\) 蒟蒻提供一种思路 因为求的是最近的车对吧\(qwq\) 所以我们可以用一个\(while\)循环所以没必要去用什么 \(for...\) 至于这是\(d ...
- [C陷阱和缺陷] 第4章 连接
一个C程序可能是由多个分别编译的部分组成,这些不同部分通过连接器合并成一个整体.在本章中,我们将考查一个典型的连接器,注意它是如何对C程序进行处理的,从而归纳出一些由于连接器的特点而可能导致的错误. ...
- php 页面展示
php 页面展示 复杂逻辑. 段落注释
- 全面学习ORACLE Scheduler特性(2)管理jobs
1.2 管理Jobs 1.2.1 启用Jobs 前面创建JOB时,由于未显式的指定ENABLED参数,因此即使指定了START_DATE,不过默认情况下JOB不会自动执行.对于这种情况,DBMS_ ...
- Windows下重置MySQL密码【MYSQL】
使用环境:win10 x64企业版 关闭正在运行的MySQL服务. 打开DOS窗口,转到mysqlbin目录. 输入mysqld --skip-grant-tables回车.如果没有出现提示信息,那就 ...
- Spark性能优化指南-高级篇(spark shuffle)
Spark性能优化指南-高级篇(spark shuffle) 非常好的讲解
- LN : leetcode 263 Ugly Number
lc 263 Ugly Number lc 263 Ugly Number Write a program to check whether a given number is an ugly num ...
- 通俗理解LDA主题模型(boss)
0 前言 看完前面几篇简单的文章后,思路还是不清晰了,但是稍微理解了LDA,下面@Hcy开始详细进入boss篇.其中文章可以分为下述5个步骤: 一个函数:gamma函数 四个分布:二项分布.多项分布. ...
- 基于APE物理引擎的管线容积率计算方法
容积率一般应用在房地产开发中,是指用地范围内地上总建筑面积与项目总用地面积的比值,这个参数是衡量建设用地使用强度的一项非常重要的指标.在其他行业,容积率的计算也非常重要,如产品利用率.管道使用率等等. ...