Codeforces Gym 100531D Digits 暴力
#Problem D. Digits
##题目连接:
http://codeforces.com/gym/100531/attachments
##Description
Little Petya likes integers. Recently he has learned about different properties of sums of number’s digits.
For example, if the sum of number’s digits is divisible by 9, then the number itself is divisible by 9 as
well.
Now little Petya is interested in numbers with equal sum of digits. He asks his older brother Dima to find
n positive integers with equal sum of digits and minimal possible total sum. Dima has other important
things to do, so he asked you to write a program that solves this problem for him.
##Input
Input file contains a single integer n (1 ≤ n ≤ 5000)
##Output
Output the minimal possible sum of n positive integers, that all have same sum of digits.
##Sample Input
2
##Sample Output
11
##Hint
题意
给你n,你需要找n个数,这n个数的数位和是相同的
求这n个数的最小和
题解:
千万不要想多了,直接暴力!
直接暴力。
代码
#include<bits/stdc++.h>
using namespace std;
int get(int x)
{
int sum = 0;
while(x)
{
sum += (x%10);
x/=10;
}
return sum;
}
map<int,long long>ans;
map<int,long long>vis;
map<int,long long>sum;
int main()
{
freopen("digits.in","r",stdin);
freopen("digits.out","w",stdout);
for(int i=1;i<=6000000;i++)
{
int k = get(i);
vis[k]++;
sum[k]+=i;
if(ans[vis[k]]==0)
ans[vis[k]]=sum[k];
else
ans[vis[k]]=min(ans[vis[k]],sum[k]);
}
int n;
while(cin>>n)
cout<<ans[n]<<endl;
}
Codeforces Gym 100531D Digits 暴力的更多相关文章
- Gym 100531D Digits (暴力)
题意:给定一个数字,问你找 n 个数,使得这 n 个数各位数字之和都相等,并且和最小. 析:暴力,去枚举和是 1 2 3...,然后去选择最小的. 代码如下: #pragma comment(link ...
- Codeforces Gym 100418K Cards 暴力打表
CardsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action? ...
- Codeforces Gym 101190M Mole Tunnels - 费用流
题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...
- Codeforces Gym 101252D&&floyd判圈算法学习笔记
一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...
- Codeforces Gym 101623A - 动态规划
题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...
- 【Codeforces Gym 100725K】Key Insertion
Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...
- Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】
2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...
- codeforces gym 100553I
codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...
- CodeForces Gym 100213F Counterfeit Money
CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...
随机推荐
- HP-Socket
HP-Socket 是一套通用的高性能 TCP/UDP 通信框架,包含服务端组件.客户端组件和Agent组件,广泛适用于各种不同应用场景的 TCP/UDP 通信系统,提供 C/C++.C#.D ...
- SoapUI Property
1. Test Suite(Case) Property 选择Test Suite(Case),switch to Custom properties 在request中的引用方式: ${[scope ...
- 记录一次cefsharp1输入法在win7下异常解决定位
最近几天都被基于cefSharp封装的浏览器控件搞疯了!对于cefSharp基本满足当前所做项目的需求,但是有一个问题一直困扰我,那就是系统中偶尔会出现输入法不能转换到中文.而且这个问题似乎没有什么规 ...
- PHP 新建动态类的代码
$testObject=(object)array(); $testObject->first="firstValue"; var_dump($testObject); $t ...
- android LocalActivityManager说明
类概述 Helper class for managing multiple running embedded activities in the same process. This c ...
- CreateThread函数&&CString::GetBuffer函数
对这个两个常见的windows下的函数学习了一下: //最简单的创建多线程实例 #include <stdio.h> #include <windows.h> //子线程函数 ...
- c/c++工程中外部头文件及库添加方法
在VS工程中,添加c/c++工程中外部头文件及库的基本步骤: 1.添加工程的头文件目录:工程---属性---配置属性---c/c++---常规---附加包含目录:加上头文件存放目录. 2.添加文件引用 ...
- Python线程
原文出处: AstralWind 1. 线程基础 1.1. 线程状态 线程有5种状态,状态转换的过程如下图所示: 1.2. 线程同步(锁) 多线程的优势在于可以同时运行多个任务(至少感觉起来是这样). ...
- Hibernate中openSession() 与 getCurrentSession()的区别
1 getCurrentSession创建的session会和绑定到当前线程,而openSession每次创建新的session. 2 getCurrentSession创建的线程会在事务回滚或事物提 ...
- 子元素过滤器nth-child解释
jQuery中的子元素过滤器nth-child是指:选取每个父元素下的第index个子元素或者奇偶元素(index从1算起) 这里有几点要注意: 1. index 从1开始算 2. 过滤器filter ...