【Yellow Cards CodeForces - 1215A 】【贪心】
该题难点在于求最小的离开数,最大的没什么好说的,关键是求最小的。
可以这样去想,最小的离开数就是每个人获得的牌数等于他所能接受的最大牌数-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);
}
【Yellow Cards CodeForces - 1215A 】【贪心】的更多相关文章
- A. Yellow Cards ( Codeforces Round #585 (Div. 2) 思维水题
---恢复内容开始--- output standard output The final match of the Berland Football Cup has been held recent ...
- Codeforces Round #585 (Div. 2) A. Yellow Cards(数学)
链接: https://codeforces.com/contest/1215/problem/A 题意: The final match of the Berland Football Cup ha ...
- [C++]Yellow Cards - GYM - 102348A(Practice *) - CodeForces
1 Problem Description Problem The final match of the Berland Football Cup has been held recently. Th ...
- CodeForces - 893D 贪心
http://codeforces.com/problemset/problem/893/D 题意 Recenlty Luba有一张信用卡可用,一开始金额为0,每天早上可以去充任意数量的钱.到了晚上, ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划
There are n people and k keys on a straight line. Every person wants to get to the office which is l ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 828D) - 贪心
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...
- CodeForces - 93B(贪心+vector<pair<int,double> >+double 的精度操作
题目链接:http://codeforces.com/problemset/problem/93/B B. End of Exams time limit per test 1 second memo ...
- C - Ordering Pizza CodeForces - 867C 贪心 经典
C - Ordering Pizza CodeForces - 867C C - Ordering Pizza 这个是最难的,一个贪心,很经典,但是我不会,早训结束看了题解才知道怎么贪心的. 这个是先 ...
- Codeforces 570C 贪心
题目:http://codeforces.com/contest/570/problem/C 题意:给你一个字符串,由‘.’和小写字母组成.把两个相邻的‘.’替换成一个‘.’,算一次变换.现在给你一些 ...
随机推荐
- 不了解这12个语法糖,别说你会Java!
阅读本文大概需要 10 分钟. 作者:Hollis 本文从 Java 编译原理角度,深入字节码及 class 文件,抽丝剥茧,了解 Java 中的语法糖原理及用法,帮助大家在学会如何使用 Java 语 ...
- kafka作为elk缓存使用
ELK集群在大规模的日志收集中面临着数据量大,收集不及时,或宕机的风险,可以选择单节点的redis,但是相比redis,kafka集群高可用的特性,更优,下面来配置kafka集群配置elk作为缓存的方 ...
- js2048小游戏
js2048小游戏,方格是怎么合并和移动的 index.html <html> <head> <meta charset="utf-8"> &l ...
- vue-router学习笔记(一)
学习vue-router首先要认识的两个属性 $router 和 $route. $router指的是router实例,$route则是当前激活的路由信息对象,是只读属性,不可更改,但是可以watch ...
- Java 在 Word 文档中使用新文本替换指定文本
创作一份文案,经常会高频率地使用某些词汇,如地名.人名.人物职位等,若表述有误,就需要整体撤换.文本将介绍如何使用Spire.Doc for Java,在Java程序中对Word文档中的指定文本进行替 ...
- 如何用Python制作优美且功能强大的数据可视化图像
第一个案例 首先开始来绘制你的第一个图表 from pyecharts import Bar '''遇到不懂的问题?Python学习交流群:1004391443满足你的需求,资料都已经上传群文件,可以 ...
- Scala 匹配模式
模式匹配 // Scala是没有Java中的switch case语法的,相对应的,Scala提供了更加强大的match case语法,即模式匹配,类替代switch case,match case也 ...
- k8s-Label(标签)
k8s-Label(标签) 一.Label是什么? Label是Kubernetes系统中的一个核心概念.Label以key/value键值对的形式附加到各种对象上,如Pod.Service.RC.N ...
- 关于redis key命名规范的设计
一.实现目标 简洁,高效,可维护 二.键值设计规约 1 . Redis key命名风格 [推荐]Redis key命名需具有可读性以及可管理性,不该使用含义不清的key以及特别长的key名: [强制] ...
- latex在vim中的代码片段
Gilles Castel写的vim中使用的代码片段,质量很高,原文:https://github.com/gillescastel 下载后,存放到 ~/.vim/plugged/ultisnips/ ...