【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 题意:给你一个字符串,由‘.’和小写字母组成.把两个相邻的‘.’替换成一个‘.’,算一次变换.现在给你一些 ...
随机推荐
- mysql 主从 数据不一致
用pt-table-checksum校验数据一致性 Jun 4th, 2013 主从数据的一致性校验是个头疼的问题,偶尔被业务投诉主从数据不一致,或者几个从库之间的 数据不一致,这会令人沮丧.通常我们 ...
- Spring Security教程之加点密,加点盐(七)
一.概述 一般用数据库保存用户的密码都是经过加密,甚少使用明文.同时,加密方式一般采用不可逆的加密方法,如MD5.也要避免相同的密码在加密后有相同的密文,如admin用户的密码为admin,加密后变成 ...
- BuaaRedSun团队博客目录——北航社团项目
目录 一.Scrum Meeting 1. Alpha 2. Beta 3. Gamma 二.测试报告 三.发布说明 四.技术博客 后端 前端 五.习得的软工原理/方法/技能? Alpha Beta ...
- python的值传递与引用传递
首先还是应该科普下函数参数传递机制,传值和传引用是什么意思? 函数参数传递机制问题在本质上是调用函数(过程)和被调用函数(过程)在调用发生时进行通信的方法问题.基本的参数传递机制有两种:值传递和引用传 ...
- SQL Server -----创建sqlserver 数据库 、表
新建数据库 1.右击 选择新建数据库 2.起一个名字 选择保存位置 3.放在之前建好的的文件夹中 点击确定 4.都要选择好 点击确定 5.确定之后如图 6.新建表 7.见一个表,常说的要满足三大 ...
- 在电脑上远程连接你的 云服务器( ECS)
在与服务器上一般安装的主流操作系统 linux 和 windowsServer linux一般都是centOs系列 这个主要是连接windowsServer 系统 用xshell ,win ...
- ubuntn18 docker zabbix+grafana安装和使用
在ubuntu docker inflxudb(安装 使用 备份 还原 以及python编码) telegraf Grafana我采用telegraf采集数据, 本文计划采用zabbix来才采集数据, ...
- 【leetcode-49】字母异位词分组
给定一个字符串数组,将字母异位词组合在一起.字母异位词指字母相同,但排列不同的字符串. 示例: 输入: ["eat", "tea", "tan&quo ...
- 【java】java 读写文件
场景:JDK8 将上传的文件,保存到服务器 Java读写文件操作: MultipartFile file InputStream inputStream = file.getInputStream( ...
- 部署CentOS虚拟机集群
1.在虚拟机中安装CentOS (1)使用CentOS-6.5-i386-minimal.iso.(2)创建虚拟机:打开Virtual Box,点击“新建”按钮,点击“下一步”,输入虚拟机名称为esh ...