洛谷 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[ ...
随机推荐
- Python序列——元组
元组是什么 1 创建元组 2 访问元组中的值 3 更新元组中的元素 4 删除元组中的元素或者元组本身 元组相关操作 内建函数对元组的支持 1 序列类型函数 2 元组内建函数 元组的特殊性 1. 元组是 ...
- Appium基础——one demo
启动模拟器,启动appium android avd启动模拟器管理 选择一个版本启动 安装appium-client 直接pip install appium-python-client安装 ...
- Android高手应该精通哪些内容
很多Android开发者已经度过了初级.中级,如何成为一个Android高手呢? Android123就各个级别的程序员应该掌握哪些内容作为下面分类. 一.初级 1. 拥有娴熟的Java基础,理解设计 ...
- hdu 1004 Let the Balloon Rise 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 用STL 中的 Map 写的 #include <iostream> #includ ...
- touch实现滑动删除
请用chrome手机模式查看或者在手机上查看(转载请注明出处) <!DOCTYPE html> <html> <head> <meta charset=&qu ...
- hdu-5762 Teacher Bo(抽屉原理+暴力)
题目链接: Teacher Bo Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- [练习]使用dx.bat、dexdump.exe、javap、Baksmali
PART0 这几个工具的关系可以这样描述: 用例: public class Hello { public int foo(int a , int b ) { return (a+b) * (a-b) ...
- LuoguP4861 按钮
传送门 这题一眼看上去要解\(k^x \equiv 1(mod\ m)\)的最小正整数解. 于是我打了一个扩展BSGS 这题这样做算的答案一直是0的.不过有另一个定理欧拉定理,\(k^{\varphi ...
- java-swingButton
package com.http; import java.awt.*; import java.awt.event.*; import javax.swing.*; import com.http. ...
- html5 WebWorkers 防止浏览器假死
在Web开发的时候经常会遇到浏览器不响应事件进入假死状态,甚至弹出“脚本运行时间过长“的提示框,如果出现这种情况说明你的脚本已经失控了. 一个浏览器至少存在三个线程:js引擎线程(处理js).GUI渲 ...