【BZOJ】2014: [Usaco2010 Feb]Chocolate Buying(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=2014
这应该是显然的贪心吧,先排序,然后按花费取
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%lld", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr2(a, b, c) for1(i, 1, b) { for1(j, 1, c) cout << a[i][j]; cout << endl; }
#define printarr1(a, b) for1(i, 1, b) cout << a[i]; cout << endl
typedef long long ll;
inline const ll getint() { ll r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const ll min(const ll &a, const ll &b) { return a<b?a:b; } const int N=100005;
struct dat { ll c, w; }a[N];
bool cmp(const dat &a, const dat &b) { return a.c<b.c; }
ll V, ans; int n; int main() {
read(n); read(V);
for1(i, 1, n) read(a[i].c), read(a[i].w);
sort(a+1, a+1+n, cmp);
for1(i, 1, n) {
if(V<a[i].c) break;
ll t=V/a[i].c;
t=min(t, a[i].w);
ans+=t;
V-=a[i].c*t;
}
print(ans);
return 0;
}
Description
巧克力品种
|
单价
|
1
2 3 4 5 |
5
1 10 7 60 |
3
1 4 2 1 |
|
|
|
Input
Output
Sample Input
53
11
10 4
7 2
60 1
Sample Output
HINT
Source
【BZOJ】2014: [Usaco2010 Feb]Chocolate Buying(贪心)的更多相关文章
- BZOJ 2015: [Usaco2010 Feb]Chocolate Giving( 最短路 )
裸最短路.. ------------------------------------------------------------------------------------ #include ...
- bzoj2014 [Usaco2010 Feb]Chocolate Buying
Description 贝西和其他奶牛们都喜欢巧克力,所以约翰准备买一些送给她们.奶牛巧克力专卖店里 有N种巧克力,每种巧克力的数量都是无限多的.每头奶牛只喜欢一种巧克力,调查显示, 有Ci头 ...
- [Usaco2010 Feb]Chocolate Buying
题目描述 贝西和其他奶牛们都喜欢巧克力,所以约翰准备买一些送给她们.奶牛巧克力专卖店里 有N种巧克力,每种巧克力的数量都是无限多的.每头奶牛只喜欢一种巧克力,调查显示, 有Ci头奶牛喜欢第i种 ...
- bzoj 2015: [Usaco2010 Feb]Chocolate Giving【spfa】
因为是双向边,所以相当于两条到1的最短路和,先跑spfa然后直接处理询问即可 #include<iostream> #include<cstdio> #include<q ...
- 2015: [Usaco2010 Feb]Chocolate Giving
2015: [Usaco2010 Feb]Chocolate Giving Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 269 Solved: 1 ...
- [bzoj 1782] [Usaco2010 Feb]slowdown慢慢游
[bzoj 1782] [Usaco2010 Feb]slowdown慢慢游 Description 每天Farmer John的N头奶牛(1 <= N <= 100000,编号1-N)从 ...
- BZOJ 1782: [Usaco2010 Feb]slowdown 慢慢游( BIT + dfs )
orz...hzwer 对着大神的 code 看 , 稍微理解了. 考虑一只牛到达 , 那它所在子树全部 +1 , 可以用BIT维护 --------------------------------- ...
- 【BZOJ】2015: [Usaco2010 Feb]Chocolate Giving(spfa)
http://www.lydsy.com/JudgeOnline/problem.php?id=2015 这种水题真没啥好说的.. #include <cstdio> #include & ...
- bzoj2015 [Usaco2010 Feb]Chocolate Giving
Description Farmer John有B头奶牛(1<=B<=25000),有N(2*B<=N<=50000)个农场,编号1-N,有M(N-1<=M<=10 ...
随机推荐
- JMeter 一:Elements of a Test Plan
参考:http://jmeter.apache.org/usermanual/test_plan.html 最小测试集包括:Test Plan,一个Thread Group,以及一个或多个Sample ...
- 2014小米,百度,pptv,去哪儿笔试题目回忆
今天一共笔试了这四家,真累啊,上午10点小米,下午2点百度,下午3点PPTV,下午5点去哪儿,今天右手太酸了,打的都话了50左右,如果没面试通知,那我可亏大了 小米就三题: 1.一个数组,排序要求,所 ...
- 【MVC5】日期选择控件DatePicker
项目中使用了Bootstrap,日期控件就选择了依赖于bootstrap的DatePicker. 在App_Start\BundleConfig.cs中引用css和js文件: bundles.Add( ...
- bootstrap的两种在input框里面增加一个图标的方式
具体代码如下: <div class="input-group"> <div class="input-icon-group"> < ...
- mac 安装2个xcode 时会导致找不到xcodebuild
mac 安装2个xcode 时会导致找不到xcodebuild 解决方案: sudo xcode-select --switch /Applications/Xcode.app/Contents/D ...
- Android中的倒计时实现
一.android.os包下提供了倒计时的抽象工具类: public abstract class CountDownTimer { /** * Millis since epoch when ala ...
- Ubuntu11.04中如何将pycharm添加到系统的“应用程序”菜单里 (pycharm已成功安装)
默认排序 Stu.zhouyc 21 人赞同了该回答 tools---->create desktop entry...不是很方便吗? 发布于 2016-04-09 21添加评论 分享 收藏 ...
- 什么是SQL注入式攻击?
什么是SQL注入式攻击? 所谓SQL注入式攻击,就是攻击者把SQL命令插入到Web表单的输入域或页面请求的查询字符串,欺骗服务器执行恶意的SQL命令.在某些表单中,用户输入的内容直接用来构造(或者影响 ...
- 分布式协调服务ZooKeeper工作原理
分布式协调服务ZooKeeper工作原理 原创 2016-02-19 杜亦舒 性能与架构 性能与架构 性能与架构 微信号 yogoup 功能介绍 网站性能提升与架构设计 大数据处理框架Hadoop.R ...
- python得到今天前的七天每天日期
import datetime d = datetime.datetime.now() def day_get(d): # 通过for 循环得到天数,如果想得到两周的时间,只需要把8改成15就可以了. ...