Content

有 \(k_2\) 个 \(2\)、\(k_3\) 个 \(3\)、\(k_5\) 个 \(5\) 和 \(k_6\) 个 \(6\),你可以用这里面的数字来组成 \(256,32\) 两种数字,试求出组成数字的总和的最大值。

数据范围:\(0\leqslant k_2,k_3,k_5,k_6\leqslant 5\times 10^6\)。

Solution

我们很容易想到这样一个贪心的思路:先尽可能多地组合成 \(256\),在尽可能多地组成 \(32\)。 所以,我们先看能组成多少个 \(256\),很显然答案是 \(\min\{k_2,k_5,k_6\}\)。然后把 \(2,5,6\) 的个数都减去这个数。设减掉以后 \(2,5,6\) 的个数分别是 \(k'_2,k'_5,k'_6\)。然后再看能够组成多少个 \(32\),很显然答案就是 \(\min\{k'_2,k_3\}\)。最后答案就是 \(\min\{k_2,k_5,k_6\}\times 256+\min\{k_2-\min\{k_2,k_5,k_6\},k_3\}\times32\)。

Code

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std; int k2, k3, k5, k6, ans; int main() {
scanf("%d%d%d%d", &k2, &k3, &k5, &k6);
int num256 = min(k2, min(k5, k6));
ans += num256 * 256, k2 -= num256, k5 -= num256, k6 -= num256;
int num32 = min(k3, k2);
ans += num32 * 32, k3 -= num32, k2 -= num32;
printf("%d", ans);
return 0;
}

CF734B Anton and Digits 题解的更多相关文章

  1. Codeforces Round #379 (Div. 2) B. Anton and Digits 水题

    B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton fou ...

  2. 【81.37%】【codeforces 734B】Anton and Digits

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. CF1104A Splitting into digits 题解

    Content 给定一个数字 \(n\),试将这个数分成若干个数,使得这些数都相等,输出任意一个方案均可. 数据范围:\(1\leqslant n\leqslant 1000\). Solution ...

  4. CF102B Sum of Digits 题解

    Content 给定一个数 \(n\),每次操作可以将 \(n\) 变成 \(n\) 各位数之和.问你几次操作之后可以将 \(n\) 变为一位数. 数据范围:\(1\leqslant n\leqsla ...

  5. Codeforces Round #379 (Div. 2) A B C D 水 二分 模拟

    A. Anton and Danik time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  6. Codeforces Round #379 (Div. 2) Analyses By Team:Red & Black

    A.Anton and Danik Problems: 给你长度为N的,只含'A','D'的序列,统计并输出何者出现的较多,相同为"Friendship" Analysis: lu ...

  7. 算法与数据结构基础 - 贪心(Greedy)

    贪心基础 贪心(Greedy)常用于解决最优问题,以期通过某种策略获得一系列局部最优解.从而求得整体最优解. 贪心从局部最优角度考虑,只适用于具备无后效性的问题,即某个状态以前的过程不影响以后的状态. ...

  8. LeetCode 842. Split Array into Fibonacci Sequence

    原题链接在这里:https://leetcode.com/problems/split-array-into-fibonacci-sequence/ 题目: Given a string S of d ...

  9. 【题解】 CF734F 【Anton and School】

    题解 CF734F [Anton and School] 传送门 这种将位运算和普通运算结合起来的题目要拆位来考虑,可以得到\(log_{2}(\)值域\()\)的算法,甚至将值域看成常数. 根据 \ ...

随机推荐

  1. JavaScript高级程序设计读后感(一)之零碎知识点查漏补缺

    目录 1-script延迟脚本defer及异步脚本async,区别及应用场景 2-未声明的变量,未初始化变量 3-Number parseInt 字符串转数值 ,进制转换 4-undefined &a ...

  2. springboot启动流程1

    public SpringApplication(ResourceLoader resourceLoader, Class<?>... primarySources) { this.res ...

  3. 网站每日UV数据指标去重统计

    package com.iexecloud.cloud.casemanager;import redis.clients.jedis.Jedis;import java.text.SimpleDate ...

  4. Kubernetes Pod 全面知识

    Pod 是在 Kubernetes 中创建和管理的.最小的可部署的计算单元,是最重要的对象之一.一个 Pod 中包含一个或多个容器,这些容器在 Pod 中能够共享网络.存储等环境. 学习 Kubern ...

  5. Scrapy-Splash的安装和使用

    Scrapy-Splash是一个Scrapy中支持JavaScript渲染的工具. Scrapy-Splash的安装分为两部分.一个是Splash服务的安装,具体是通过Docker,安装之后,会启动一 ...

  6. 表格合并单元格【c#】

    gridBranchInfo.DataSource = dtBranchViewList; gridBranchInfo.DataBind(); Random random = new Random( ...

  7. A Child's History of England.40

    Excommunication was, next to the Interdict I told you of at the close {end} of the last chapter, the ...

  8. accent, access, accident

    accent A colon (:) is used to represent a long vowel [元音], e.g. sheet /ʃiːt/ and shit /ʃit/. The wor ...

  9. Python3的类注意事项

    参考: https://www.runoob.com/python/python-object.html https://www.runoob.com/w3cnote/python-extends-i ...

  10. OSGI与Spring结合开发web工程

    简介: 作为一个新的事实上的工业标准,OSGi 已经受到了广泛的关注, 其面向服务(接口)的基本思想和动态模块部署的能力, 是企业级应用长期以来一直追求的目标.Spring 是一个著名的 轻量级 J2 ...