题目描述

Dpstr开了个饮料连锁店,连锁店共有n家,出售的饮料种类相同。为了促销,Dpstr决定让每家连锁店开展赠送活动。具体来说,在第i家店,顾客可以用ai个饮料瓶兑换到bi瓶饮料和1个纪念币(注意不足ai个饮料瓶则不能兑换)。一家店可以兑换多次,兑换得到的饮料瓶还可以继续用于兑换。

小C买了s瓶饮料,他想知道用这s瓶饮料最多可以兑换到多少个纪念币。

数据范围

对于30%的数据,0≤n≤10,0≤s≤20;

对于50%的数据,0≤n≤1,000,0≤s≤100,000;

对于100%的数据,0≤n≤100,000,0≤s≤10^19,0≤ai≤10^19,0≤bi≤10^19。

解法

贪心:以差值为第一关键字,x为第二关键字,尽可能做靠前的。

代码

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define ll long long
using namespace std;
const char* fin="store.in";
const char* fout="store.out";
const unsigned ll inf=0x7fffffff;
const unsigned ll maxn=100007;
unsigned ll n,m,i,j,k,ans;
struct node{
unsigned ll x,y;
}a[maxn];
bool cmp(node a,node b){
return a.y<b.y || a.y==b.y && a.x<b.x;
}
int main(){
freopen(fin,"r",stdin);
freopen(fout,"w",stdout);
scanf("%llu%llu",&n,&m);
for (i=1;i<=n;i++){
scanf("%llu%llu",&a[i].x,&a[i].y);
a[i].y=a[i].x-a[i].y;
}
sort(a+1,a+n+1,cmp);
for (i=1;i<=n;i++){
if (m>=a[i].x){
if (a[i].y<=0){
printf("-1");
return 0;
}
k=(m-a[i].x)/a[i].y+1;
ans+=k;
m-=k*a[i].y;
}
}
printf("%llu",ans);
return 0;
}

启发

输出unsigned时使用%llu,实在不行,用cout

最新文章

  1. 利用NSCalendar类实现日期的比较
  2. nginx:403 forbidden 二种原因
  3. 使用Windows Azure创建和发布ASP.NET应用程序
  4. JUnit单元测试--小试牛刀
  5. [Ruby学习总结]Ruby中的类
  6. Centos6.5 mysql折腾记
  7. windows7 64位安装tensorflow 1.4.0 CPU版本
  8. 定时器setTimeout实现函数节流
  9. vue axios 与 FormData 结合 提交文件 上传文件
  10. @media screen and (max-width: 960px)与@media (max-width: 960px) 有screen与没有screen的区别
  11. Zynq ZC706 传统方式移植Linux -- 编译u-boot
  12. python scrapy 调试模式
  13. Ubuntu常用安装源
  14. 转:Web优化 及常用工具包
  15. html---规范、细节积累-01
  16. Go语言中字符串的查找方法小结
  17. VS2010对c++11的支持情况验证
  18. SVN 操作报错 “Previous operation has not finished; run &#39;cleanup&#39; if it was interrupted“
  19. 关闭了的SQL Server服务如何打开
  20. mysql数据库优化课程---12、mysql嵌套和链接查询

热门文章

  1. Python实例3-字符图网格
  2. 2019-8-31-dotnet-控制台读写-Sqlite-提示-no-such-table-找不到文件
  3. mysql 登录的时候设置编码 utf8
  4. Django项目:CRM(客户关系管理系统)--21--13PerfectCRM实现King_admin分页页数
  5. Spring配置xml自动提示——转载https://blog.csdn.net/sinat_18474835/article/details/79370629
  6. [转载]C语言EOF是什么?
  7. 在多版本python的pip的安装与对应包的安装
  8. Vue. 之 Element table 高度自适应
  9. php的FTP操作类
  10. 【洛谷】 P1420 最长连号