BZOJ 1685/Luogu 2376: [Usaco2005 Oct]Allowance 津贴
来源:互联网 发布:淘宝取消退款申请手机 编辑:程序博客网 时间:2024/04/28 19:48
想来水一波贪心 然后发现智障的我想不到这题 打脸
有一个很重要的条件 大面值是所有小面值的整数倍
首先肯定多的越少越好
然后你肯定从大到小来贪嘛
如果不能刚好满足 再拿最小的让他超过那个值
#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>using namespace std;const int inf=1<<29;inline int read(){ char ch=getchar(); int x=0,f=1; while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();} return x*f;}struct node{int x,y;}a[21];int h[21];int Cmp(node x1,node x2){return x1.x<x2.x;}int main(){ int i,j,n=read(),m=read(); for(i=1;i<=n;i++)a[i].x=read(),a[i].y=read(); sort(a+1,a+1+n,Cmp); int ans=0; for(i=n;i>0;i--) if(a[i].x>=m)ans+=a[i].y; else break; while(1) { int s=m; for(j=i;j>0;j--) { int t=min(a[j].y,s/a[j].x); s-=a[j].x*t,h[j]=t; } if(s>0) for(j=1;j<=i && s>0;j++) if(a[j].y>h[j])s-=a[j].x,h[j]++; if(s<=0) { int t=inf; for(j=1;j<=i;j++)if(h[j])t=min(t,a[j].y/h[j]); ans+=t; for(j=1;j<=i;j++)if(h[j])a[j].y-=t*h[j]; } else break; } printf("%d\n",ans); return 0;}
1 0
- BZOJ 1685/Luogu 2376: [Usaco2005 Oct]Allowance 津贴
- 1685: [Usaco2005 Oct]Allowance 津贴
- bzoj 1685: [Usaco2005 Oct]Allowance 津贴(贪心)
- [Usaco2005 Oct]Allowance 津贴
- 【洛谷 2376】 [USACO09OCT]津贴Allowance
- bzoj 1684: [Usaco2005 Oct]Close Encounter
- 洛谷 P2376 [USACO09OCT]津贴Allowance
- bzoj1684 [Usaco2005 Oct]Close Encounter
- 1684: [Usaco2005 Oct]Close Encounter
- [bzoj1684][Usaco2005 Oct]Close Encounter
- bzoj1744 [Usaco2005 oct]Skiing 奶牛滑雪
- Allowance
- Allowance
- BZOJ [Usaco2008 Oct]牧场行走
- BZOJ 1601 [Usaco2008 Oct]灌水
- bzoj 1601 [Usaco2008 Oct]灌水
- bzoj 1601: [Usaco2008 Oct]灌水
- [BZOJ]1601: [Usaco2008 Oct]灌水
- Mybatis学习笔记六:集成SpringMVC
- Mysql系列(三)数据库特性
- Windows环境下编译x264库
- DB2中字符、数字和日期类型之间的转换
- 解析大数据基准测试——TPC-H or TPC-DS
- BZOJ 1685/Luogu 2376: [Usaco2005 Oct]Allowance 津贴
- Intent之隐式意图 setAction的使用
- Hadoop问题集锦:Unauthorized request to start container
- FFT results in spectrum alising,picket fence effect, spectrum leakage, spectrum interference
- 大规模图搜索和实时计算在阿里反作弊系统中的应用
- quartz学习记录
- 清除浮动
- 第十一周 循环画三角形
- spring之BeanFactory创建bean原理模拟