洛谷 P2376 [USACO09OCT]津贴Allowance
https://www.luogu.org/problemnew/show/P2376
看了题解做的,根本不会贪心。。
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
int n,c;
int ans;
pii t1[];
int len;
int main()
{
int t,i,x,y,s;
bool fl;
scanf("%d%d",&n,&c);
for(i=;i<=n;i++)
{
scanf("%d%d",&x,&y);
if(x>=c) ans+=y;
else t1[++len]=mp(x,y);
}
sort(t1+,t1+len+);
while()
{
fl=;
for(i=;i<=len;i++)
if(t1[i].se!=)
fl=;
if(!fl) break;
s=;
for(i=len;i>=;i--)
{
t=min(t1[i].se,(c-s)/t1[i].fi);
s+=t1[i].fi*t;
t1[i].se-=t;
}
if(s<c)
{
fl=;
for(i=;i<=len;i++)
if(t1[i].se!=)
fl=;
if(!fl) break;
for(i=;i<=len;i++)
if(t1[i].se)
{
--t1[i].se;
break;
}
}
ans++;
}
printf("%d",ans);
return ;
}
洛谷 P2376 [USACO09OCT]津贴Allowance的更多相关文章
- 洛谷 P2376 [USACO09OCT]津贴Allowance 解题报告
P2376 [USACO09OCT]津贴Allowance 题目描述 作为创造产奶纪录的回报,\(Farmer\) \(John\)决定开始每个星期给\(Bessie\)一点零花钱. \(FJ\)有一 ...
- P2376 [USACO09OCT]津贴Allowance
P2376 [USACO09OCT]津贴Allowance一开始想的是多重背包,但是实践不了.实际是贪心,让多c尽可能少,所以先放大的,最后让小的来弥补. #include<iostream&g ...
- 洛谷——P2958 [USACO09OCT]木瓜的丛林Papaya Jungle
P2958 [USACO09OCT]木瓜的丛林Papaya Jungle 题目描述 Bessie has wandered off the farm into the adjoining farmer ...
- 洛谷—— P1339 [USACO09OCT]热浪Heat Wave
P1339 [USACO09OCT]热浪Heat Wave 题目描述 The good folks in Texas are having a heatwave this summer. Their ...
- 洛谷 P2959 [USACO09OCT]悠闲漫步The Leisurely Stroll
P2959 [USACO09OCT]悠闲漫步The Leisurely Stroll 题目描述 Bessie looks out the barn door at the beautiful spri ...
- 洛谷 P2960 [USACO09OCT]Milkweed的入侵Invasion of the Milkweed
P2960 [USACO09OCT]Milkweed的入侵Invasion of the Milkweed 题目描述 Farmer John has always done his best to k ...
- 洛谷 P2958 [USACO09OCT]木瓜的丛林Papaya Jungle
P2958 [USACO09OCT]木瓜的丛林Papaya Jungle 题目描述 Bessie has wandered off the farm into the adjoining farmer ...
- 洛谷P1339 [USACO09OCT]热浪Heat Wave 题解
题目传送门 这道题实际非常简单好奇是怎么变黄的... 其实也就是一个SPFA,本人非常懒,不想打邻接表,直接用矩阵就好啦... #include<bits/stdc++.h> using ...
- 洛谷 P2639 [USACO09OCT]Bessie的体重问题Bessie's We… 题解
题目传送门 这也是个01背包,只是装的很... #include<bits/stdc++.h> #define MAXN 45010 using namespace std; int f[ ...
随机推荐
- CSS控制文本的长度,超过一行显示省略号
代码如下: <div style="width:100px;height:20px;text-overflow:ellipsis; white-space:nowrap; overfl ...
- CAS无锁机制原理
原子类 java.util.concurrent.atomic包:原子类的小工具包,支持在单个变量上解除锁的线程安全编程 原子变量类相当于一种泛化的 volatile 变量,能够支持原子的和有条件的读 ...
- opengl in medical imaging
医学可视化 http://schorsch.efi.fh-nuernberg.de/roettger/index.php/Lectures/MedicalVisualization http://ww ...
- html5--3.13 表单的新增属性
html5--3.13 表单的新增属性 学习要点 掌握表单新增属性的使用 HTML5新增表单属性 之前课程中已经接触过的新增属性:autocomplete属性/autofocus属性/list属性/m ...
- php数组合并
php的数合并函数: array_merge($arr1, $arr2, ..., $arr{$n}); 如果数组的键名有重复,后面的会覆盖前面的. 如果键名是数字索引,则会重新排列索引,往后累加. ...
- 【转载】Unity3D的断点调试功能
原文链接:http://liweizhaolili.blog.163.com/blog/static/162307442013214485190/ 断点调试功能可谓是程序员必备的功能了.Unit ...
- 随应潮流-基于ABP+Angularjs现代化应用软件开发框架(1)-总体介绍
系列文章目录 随应潮流-基于ABP+Angulsrjs现代化应用软件开发框架(1)-总体说明 随应潮流-基于ABP+Angulsrjs现代化应用软件开发框架(2)-abp说明 随应潮流-基于ABP+A ...
- Python:元组
元组:只读,不能修改,使用小括号 创建元组: tup1 = ('physics', 'chemistry', 1997, 2000) tup2 = (1, 2, 3, 4, 5 ) tup3 = &q ...
- SPOJ Find the max XOR value(二进制,贪心即可)
You have two integers L and R, and you are required to find the max xor value of a and b where L < ...
- BZOJ_3680_吊打XXX_模拟退火
BZOJ_3680_吊打XXX_模拟退火 Description gty又虐了一场比赛,被虐的蒟蒻们决定吊打gty.gty见大势不好机智的分出了n个分身,但还是被人多势众的蒟蒻抓住了.蒟蒻们将 n个g ...