该题难点在于求最小的离开数,最大的没什么好说的,关键是求最小的。

可以这样去想,最小的离开数就是每个人获得的牌数等于他所能接受的最大牌数-1,这样就可以直接比较m=a1(k1-1)+a2(k2-1)与n的大小,n-m即为最小的离开数。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<queue>
using namespace std;
typedef long long LL;
int a1, a2, k1, k2, n;
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
scanf("%d %d %d %d %d", &a1, &a2, &k1, &k2, &n);
int m = a1 * (k1 - 1) + a2 * (k2 - 1);
if(n <= m)
printf("0");
else
printf("%d", n - m);
int cnt = 0, res = n;
if(k1 > k2)
{
cnt = n / k2;
if(cnt > a2)
{
cnt = a2;
res -= cnt * k2;
}
else
res -= cnt * k2;
cnt += res / k1;
}
else
{
cnt = n / k1;
if(cnt > a1)
{
cnt = a1;
res -= cnt * k1;
}
else
res -= cnt * k1;
cnt += res / k2;
}
printf(" %d\n", cnt);
}

最新文章

  1. SQL用法操作合集
  2. java 中多线程之间的通讯之等待唤醒机制
  3. 图片javascript缩小
  4. ApkTool反编译apk,去除广告或者汉化后重新打包apk,并签名
  5. 4.6---找二叉树中序后继(CC150)
  6. oracle截取某个字符前面的字符串
  7. 标准MD5加密算法
  8. Ghost源代码
  9. Mybatis学习之JDBC缺陷
  10. swift 笔记 (二十) —— 泛型
  11. mac地址静态捆绑,防止arp欺骗
  12. java poi 导入日期为空
  13. django.db.utils.ProgrammingError: 1146 的解决办法
  14. ng-book札记——Angular工作方式
  15. c# 解决Randoms伪随机重复问题
  16. 基于GPS数据建立隐式马尔可夫模型预测目的地
  17. c#, AOP动态代理实现动态权限控制(一)
  18. SAP Brazil J1BTAX 为税收例外创建税收组(翻译)
  19. Python开发——6.文件操作
  20. Python3 简单验证码识别思路及实例

热门文章

  1. vue添加背景音乐
  2. C/C++中书写汇编指令
  3. 福州大学软件工程1916|W班 第10、11次作业成绩排名
  4. 安装gerrit服务器
  5. 解决mybatis中#{}导致的The error may involve defaultParameterMap的问题
  6. github下载速度慢甚至多次失败,通过码云的导入功能导入github项目到码云上,然后再从码云下载
  7. React组件介绍与使用(父传子、子传父、兄弟传)
  8. Windows域的创建与加入教程
  9. C# 读取配置指定Config文件--亲测通过
  10. Disable foreign key checks during import