bzoj 1685: [Usaco2005 Oct]Allowance 津贴(贪心)
1685: [Usaco2005 Oct]Allowance 津贴
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 264 Solved: 195
[Submit][Status][Discuss]
Description
As a reward for record milk production, Farmer John has decided to start paying Bessie the cow a small weekly allowance. FJ has a set of coins in N (1 <= N <= 20) different denominations, where each denomination of coin evenly divides the next-larger denomination (e.g., 1 cent coins, 5 cent coins, 10 cent coins, and 50 cent coins). Using the given set of coins, he would like to pay Bessie at least some given amount of money C (1 <= C <= 100,000,000) every week. Please help him compute the maximum number of weeks he can pay Bessie.
Input
Output
Sample Input
Sample Output
不错的贪心题
思路很简单,所有货币按面值排序,每次都尽量选择面值大的就好了,但是有很多细节要处理
use[i]表示当前周为了凑津贴第i种货币需要用use[i]个
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
typedef struct Coin
{int x, y;bool operator < (const Coin &b) const{if(x>b.x)return 1;return 0;}
}Coin;
Coin s[23];
int use[23];
int main(void)
{int n, c, i, now, ans;scanf("%d%d", &n, &c);for(i=1;i<=n;i++)scanf("%d%d", &s[i].x, &s[i].y);sort(s+1, s+n+1);ans = 0;while(1){now = c;memset(use, 0, sizeof(use));for(i=1;i<=n;i++){if(now>s[i].x){use[i] = min(now/s[i].x, s[i].y);now -= s[i].x*use[i];}}for(i=n;i>=1;i--){if(now!=0 && use[i]+1<=s[i].y){now = 0;use[i]++;break;}else if(now!=0){now += use[i]*s[i].x;use[i] = 0;}}if(now!=0)break;for(i=1;i<=n;i++)s[i].y -= use[i];ans++;}printf("%d\n", ans);return 0;
}
bzoj 1685: [Usaco2005 Oct]Allowance 津贴(贪心)相关推荐
- BZOJ 1685 [Usaco2005 Oct]Allowance 津贴:贪心【给硬币问题】
题目链接:http://begin.lydsy.com/JudgeOnline/problem.php?id=1333 题意: 有n种不同币值的硬币,并保证大币值一定是小币值的倍数. 每种硬币的币值为 ...
- bzoj 1684: [Usaco2005 Oct]Close Encounter【数学(?)】
枚举分母,然后离他最近的分子只有两个,分别判断一下能不能用来更新答案即可 #include<iostream> #include<cstdio> #include<cma ...
- bzoj1745[Usaco2005 oct]Flying Right 飞行航班*
bzoj1745[Usaco2005 oct]Flying Right 飞行航班 题意: n个农场,有k群牛要从一个农场到另一个农场(每群由一只或几只奶牛组成)飞机白天从农场1到农场n,晚上从农场n到 ...
- bzoj1684[Usaco2005 Oct]Close Encounter*
bzoj1684[Usaco2005 Oct]Close Encounter 题意: 找一个分数它最接近给出一个分数.你要找的分数的分子分母的范围在1..32767. 题解: 枚举所求分数的分子,用其 ...
- BZOJ 2151 种树(可反悔贪心,链表)【BZOJ千题计划】就图一乐
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 题目链接 https://hydro.ac/d/bzoj/p/2151 是 hydro 的 BZOJ ...
- BZOJ 2135 刷题计划(贪心,求导,二分)【BZOJ 修复工程】
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 题目链接 https://hydro.ac/d/bzoj/p/2135 是 hydro 的 BZOJ ...
- BZOJ 1692: [Usaco2007 Dec]队列变换( 贪心 )
数据 n <= 30000 , 然后 O( n² ) 的贪心也过了..... USACO 数据是有多弱啊 = = ( ps : BZOJ 1640 和此题一模一样 , 双倍经验 ) ------ ...
- bzoj 3386 bzoj 3408: [Usaco2009 Oct]Heat Wave 热浪(最短路)
3408: [Usaco2009 Oct]Heat Wave 热浪 Time Limit: 3 Sec Memory Limit: 128 MB Submit: 301 Solved: 223 [ ...
- poj 3040 Allowance (贪心
作为创纪录的牛奶生产的奖励,农场主约翰决定开始给Bessie奶牛一个小的每周津贴.FJ有一套硬币N种(1≤N≤20)不同的面额,每枚硬币是所有比他小的硬币面值的倍数,例如1美分硬币.5美分硬币.10美 ...
最新文章
- Linux学习之系统编程篇:mmap练习
- CRM和C4C product category hierarchy的可编辑性控制逻辑
- 背景透明度 下拉菜单
- leetcode - 494. 目标和
- 郭明錤:iPhone 13 Pro系列将有1TB储存空间
- iOS 数据持久化 NSUserDefault
- 云服务器部署项目:vue-cli 部署服务配置
- pcb天线设计和hfss仿真分析实例_5G天线与多天线系统设计
- Chrome OS 72.0.3626.117 发布
- 计算机服务重置,怎么重置电脑网络设置
- 视频教程-带你入门matlab小波分析-Matlab
- [中奖]第九届“泰迪杯”挑战赛A题
- 华悦网游器软件介绍及功能介绍
- 直接可以用的Python和OpenCV检测及分割图像的目标区域例子
- groovy 基础知识
- 用禅道编写测试用例(详细)
- 冰汽时代机器人不用热_如何评价游戏《冰汽时代》?
- 单纯同调与奇异同调 习题
- 常见的POS打印机分类
- Java中WeakHashMap的应用场景
热门文章
- python编程教学软件-Python编程教学app
- python手机版下载-qpython手机版下载
- python是什么-Python 是什么
- python全套教程-老王Python全套教程完整版
- php7 错误处理,PHP7升级-异常错误处理
- js的事件循环机制,同步和异步,以及宏任务与微任务的执行顺序
- 图解FFMPEG打开媒体的函数avformat_open_input
- cmd 修改ie快捷方式_windows使用技巧之Win + R 与 CMD 的不同
- 小型机oracle命令,IBM 小型机基本知识及AIX操作系统基本命令.doc
- jquery 把元素移动到另外一个元素里面