传送门

按价格排序后贪心

——代码

 #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(贪心)的更多相关文章

  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. [USACO10FEB]购买巧克力Chocolate Buying 【假背包真贪心】 By cellur925

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

  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. P2983 [USACO10FEB]购买巧克力Chocolate Buying

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

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

    https://www.luogu.org/problem/show?pid=2983 题目描述 Bessie and the herd love chocolate so Farmer John i ...

随机推荐

  1. 栗染-Error parsing D:\sdkforas\android-sdk-windows\system-images\android-24\android-wear\x86\devices.xml

    每次打开android virtual device manager 下面都会出现这样的问题 解决办法: 打开自己安装的sdk目录,找到/tools/lib/devices.xml去替换图中路径里面的 ...

  2. bzoj 1616: [Usaco2008 Mar]Cow Travelling游荡的奶牛【dp】

    写了个bfs发现MLE了... 设f[t][i][j]为在t时刻走到(i,j)的方案数,转移和bfs一样 #include<iostream> #include<cstdio> ...

  3. python自动化测试学习笔记-unittest参数化

    做接口测试的时候,当一个参数需要输入多个值的时候,就可以使用参数来实现: python中unittest单元测试,可以使用nose_parameterized来实现: 首先需要安装:pip  inst ...

  4. C# 动态调用 WebService (转)

    在 Visual Studio 中客户端程序可以添加服务引用来调用 WebService,这样 Visual Studio 会生成与之相关的代理类,通过这个代理类可以很方便的访问所需要的服务. 如果服 ...

  5. 1619. [HEOI2012]采花

    1619. [HEOI2012]采花 ★★☆   输入文件:1flower.in   输出文件:1flower.out   简单对比 时间限制:5 s   内存限制:128 MB [题目描述] 萧薰儿 ...

  6. Angular——依赖注入

    基本介绍 1.AngularJS采用模块化的方式组织代码,将一些通用逻辑封装成一个对象或函数,实现最大程度的复用,这导致了使用者和被使用者之间存在依赖关系. 2.所谓依赖注入是指在运行时自动查找依赖关 ...

  7. codeforces_302D

    D. Yaroslav and Time time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  8. MFC_2.3 定时器、滑块、进度条控件

    定时器.滑块.进度条控件 1.拖控件 2.绑定变量.默认,然后取名字 3.初始化设置定时器 // 设置滑块和进度条的范围 m_TrackBar.SetRange(0, 1000); m_StaticP ...

  9. vue组件---组件注册

    (1)组件名 在注册一个组件的时候,我们始终需要给它一个名字.比如在全局注册的时候我们已经看到了: Vue.component('my-component-name', { /* ... */ }) ...

  10. gitlab恢复、迁移

    文件说明 安装包:gitlab-ce_8.11.5-ce.0_amd64.deb 备份的数据:533751277_gitlab_backup.tar 系统:Ubuntu 16.04.4 LTS \n ...