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

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\). 所以,我们先看能…
B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6. Anton's favorite integers are 32 and 256. He decide…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6. Anton's favorite integers ar…
Content 给定一个数字 \(n\),试将这个数分成若干个数,使得这些数都相等,输出任意一个方案均可. 数据范围:\(1\leqslant n\leqslant 1000\). Solution 题目里面讲了,能够满足"所有数都相等"的序列都可以输出,那我们直接输出 \(n\),再输出 \(n\) 个 \(1\) 就好了. Code int n, k = 1; int main() { getint(n); writeint(n), putchar('\n'); _for(i, 1…
Content 给定一个数 \(n\),每次操作可以将 \(n\) 变成 \(n\) 各位数之和.问你几次操作之后可以将 \(n\) 变为一位数. 数据范围:\(1\leqslant n\leqslant 10^{10^5}\). Solution 一看这么大个数字我们就不能够用 int,long long 之类的类型读入了,只能够用字符串.字符数组.然后考虑将所有的数位暴力拆开求和,然后再代入求出操作后的数字,直到变成一位数为止. Code 请注意下面的代码需要特判是否本来就是一位数. con…
A. Anton and Danik time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Anton likes to play chess, and so does his friend Danik. Once they have played n games in a row. For each game it's known…
A.Anton and Danik Problems: 给你长度为N的,只含'A','D'的序列,统计并输出何者出现的较多,相同为"Friendship" Analysis: lucky_ji: 水题,模拟统计A和D的数目比较大小输出结果即可 Tags: Implementation B.Anton and Digits Problems: 给定k2个2,k3个3,k5个5及k6个6,可以组成若干个32或256,求所有方案中Sigma的最大值 Analysis: lucky_ji: 同…
贪心基础 贪心(Greedy)常用于解决最优问题,以期通过某种策略获得一系列局部最优解.从而求得整体最优解. 贪心从局部最优角度考虑,只适用于具备无后效性的问题,即某个状态以前的过程不影响以后的状态.紧接下来的状态仅与当前状态有关.和分治.动态规划一样,贪心是一种思路,不是解决某类问题的具体方法. 应用贪心的关键,是甄别问题是否具备无后效性.找到获得局部最优的策略.有的问题比较浅显,例如一道找零钱的题目 LeetCode 860. Lemonade Change: // 860. Lemonad…
原题链接在这里:https://leetcode.com/problems/split-array-into-fibonacci-sequence/ 题目: Given a string S of digits, such as S = "123456579", we can split it into a Fibonacci-like sequence [123, 456, 579]. Formally, a Fibonacci-like sequence is a list F o…
题解 CF734F [Anton and School] 传送门 这种将位运算和普通运算结合起来的题目要拆位来考虑,可以得到\(log_{2}(\)值域\()\)的算法,甚至将值域看成常数. 根据 \(a|b+a \& b=a+b\) 得到 \(b_i+c_i=\Sigma a_i+na_i\) 于是 \(a_i=\frac{b_i+c_i- \Sigma a_i}{n}\) 根据这个式子,直接得到\(a_i\),注意在除的时候判断整除以免非法情况出现. 此时,我们要判断\(b_i\)和\(c_…