【Yellow Cards CodeForces - 1215A 】【贪心】
2024-09-18 12:03:38
该题难点在于求最小的离开数,最大的没什么好说的,关键是求最小的。
可以这样去想,最小的离开数就是每个人获得的牌数等于他所能接受的最大牌数-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);
}
最新文章
- SQL用法操作合集
- java 中多线程之间的通讯之等待唤醒机制
- 图片javascript缩小
- ApkTool反编译apk,去除广告或者汉化后重新打包apk,并签名
- 4.6---找二叉树中序后继(CC150)
- oracle截取某个字符前面的字符串
- 标准MD5加密算法
- Ghost源代码
- Mybatis学习之JDBC缺陷
- swift 笔记 (二十) —— 泛型
- mac地址静态捆绑,防止arp欺骗
- java poi 导入日期为空
- django.db.utils.ProgrammingError: 1146 的解决办法
- ng-book札记——Angular工作方式
- c# 解决Randoms伪随机重复问题
- 基于GPS数据建立隐式马尔可夫模型预测目的地
- c#, AOP动态代理实现动态权限控制(一)
- SAP Brazil J1BTAX 为税收例外创建税收组(翻译)
- Python开发——6.文件操作
- Python3 简单验证码识别思路及实例
热门文章
- vue添加背景音乐
- C/C++中书写汇编指令
- 福州大学软件工程1916|W班 第10、11次作业成绩排名
- 安装gerrit服务器
- 解决mybatis中#{}导致的The error may involve defaultParameterMap的问题
- github下载速度慢甚至多次失败,通过码云的导入功能导入github项目到码云上,然后再从码云下载
- React组件介绍与使用(父传子、子传父、兄弟传)
- Windows域的创建与加入教程
- C# 读取配置指定Config文件--亲测通过
- Disable foreign key checks during import