poj 3040 Allowance
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 1842 | Accepted: 763 |
Description
Input
* Lines 2..N+1: Each line corresponds to a denomination of coin and
contains two integers: the value V (1 <= V <= 100,000,000) of the
denomination, and the number of coins B (1 <= B <= 1,000,000) of
this denomation in Farmer John's possession.
Output
Sample Input
3 6
10 1
1 100
5 120
Sample Output
111
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
struct TT
{
int v,w;
}a[];
int need[];
bool cmp(TT m, TT n)
{
if(m.v>n.v) return true;
return false;
}
int main()
{
int n,i,k;
int value,aa,bb,ans;
while(~scanf("%d %d",&n,&value))
{
ans = ;
k = ;
for( i=;i<n;i++)
{
scanf("%d %d",&aa,&bb);//排除大数;
if( aa>= value)
{
ans = ans+bb;
}
else
{
a[k].v = aa;
a[k].w = bb;
k++;
}
}
//k = n;
//printf("sdfgsdf\n");
sort(a,a+k,cmp);
while()
{
memset(need,,sizeof(need));
int sum = value;
for(int i=; i<k; i++) // Õý×ÅÕÒ
{
int tmp = sum/a[i].v;
need[i] = min(a[i].w,tmp);
sum = sum - a[i].v*need[i];
}
if(sum>)
{
for(int i=k-;i>=;i--)
{
if(a[i].w && a[i].v>=sum)
{
need[i]++;
sum = ;
break;
}
}
}
if(sum>) break;
int s = 0x3f3f3f3f;
for(int i=;i<k;i++)
{
if(need[i])
s = min(s,a[i].w/need[i]);
}
ans = ans+s;
for(int i=;i<k;i++)
{
if(need[i])
a[i].w -= need[i]*s;
}
}
printf("%d\n",ans);
}
return ;
}
poj 3040 Allowance的更多相关文章
- POJ 3040 Allowance【贪心】
POJ 3040 题意: 给奶牛发工资,每周至少 C 元.约翰手头上有面值V_i的硬币B_i个,这些硬币的最小公约数为硬币的最小面值.求最多能发几周? 分析: 贪心策略是使多发的面额最小(最优解).分 ...
- POJ 3040 Allowance 贪心
这题目的贪心思路还是有一点细节问题的. 还没有证明,据说是因为题目给的条件是每个价格是比它小的价格的倍数才能这么贪心的. 思路如下: 假设要给奶牛的钱为C 1)从大面值到小面值一次拿钱,能拿多少拿多少 ...
- 【贪心】Allowance POJ 3040
题目链接:http://poj.org/problem?id=3040 题目大意:你有n种不同面值的硬币,面值为vi的有bi个."硬币的面额均匀地分配下一个更大的面额",即下一个更 ...
- 【POJ - 3040】Allowance(贪心)
Allowance 原文是English,这里就放Chinese了 Descriptions: 作为创纪录的牛奶生产的奖励,农场主约翰决定开始给Bessie奶牛一个小的每周津贴.FJ有一套硬币N种(1 ...
- Greedy:Allowance(POJ 3040)
零用钱大作战 题目大意:农夫和牛又搞新花样了,现在农夫想给Bessie每个星期都给一点零用钱,农夫有一堆面值的钱币,并且这个钱币都能被上一个钱币整除(1,5,10,50),并且钱币有一定数量,要你求最 ...
- POJ 3040 贪心
贪心好题 ---. 思路: 从大到小凑C 如果不够 再从小到大补满(超过)C //By SiriusRen #include <cstdio> #include <cstring&g ...
- ProgrammingContestChallengeBook
POJ 1852 Ants POJ 2386 Lake Counting POJ 1979 Red and Black AOJ 0118 Property Distribution AOJ 0333 ...
- [SinGuLaRiTy] 贪心题目复习
[SinGuLaRiTy-1024] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. [POJ 2709] 颜料 (Painter) 题目描述 ...
- poj-3040 Allowance (贪心)
http://poj.org/problem?id=3040 FJ 有n种不同面值的硬币,每种硬币都有相应的个数,大面值的硬币值总能被小面值的硬币值整除,每周需要支付 Bessie c元,问最多能 ...
随机推荐
- kuangbin_UnionFind C (HDU 1213)
过程模板 扫一下一共有几棵树 输出 #include <iostream> #include <string> #include <cstdio> #include ...
- 9款精致HTML5/jQuery日历时钟控件源码下载(源码请见百度云) 链接:http://pan.baidu.com/s/1geIXe75 密码:7m4a
现在的网页应用越来越丰富,我们在网页中填写日期和时间已经再也不用手动输入了,而是使用各种各样的日期时间选择控件,大部分样式华丽的日期选择和日历控件都是基于jQuery和HTML5的,比如今天要分享的这 ...
- Java static block static constructor , static field
http://stackoverflow.com/questions/7121213/singleton-instantiation http://docs.oracle.com/javase/spe ...
- Python-属性(property)
在2.6版本中,添加了一种新的类成员函数的访问方式--property. 原型 class property([fget[, fset[, fdel[, doc]]]]) fget:获取属性 fset ...
- mysql学习之-三种安装方式与版本介绍
MYSQL版本介绍 mysql分alpha,beta,rc,GA四个版本. alpha 暗示这是一个以展示新特性为目的的版本,存在比较多的不稳定因素,还会向代码中添加新新特性beta 以后的beta ...
- 开放平台-web实现人人网第三方登录
应用场景 web应用通过人人网登录授权实现第三方登录. 操作步骤 1 注册成为人人网开放平台开发者 http://app.renren.com/developer ...
- wikioi 1430 素数判定
/*====================================================================== 题目描述 Description 质数又称素数.指在一 ...
- Zookeeper工作原理一
ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,它包含一个简单的原语集,分布式应用程序可以基于它实现同步服务,配置维护和命名服务等.Zookeeper是hadoop的一个子项目,其 ...
- JavaScript闭包演示
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8" /> <title&g ...
- PIP安装Python的scipy,scrapy等包出现“failed building wheel for xxx”问题解决办法
1.在这里下载对应的.whl文件,注意别改文件名! http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml Ctrl + F,输入lxml,找到下面这段 Lxm ...