#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 暴力的更多相关文章

  1. Gym 100531D Digits (暴力)

    题意:给定一个数字,问你找 n 个数,使得这 n 个数各位数字之和都相等,并且和最小. 析:暴力,去枚举和是 1 2 3...,然后去选择最小的. 代码如下: #pragma comment(link ...

  2. Codeforces Gym 100418K Cards 暴力打表

    CardsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action? ...

  3. Codeforces Gym 101190M Mole Tunnels - 费用流

    题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...

  4. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

  5. Codeforces Gym 101623A - 动态规划

    题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...

  6. 【Codeforces Gym 100725K】Key Insertion

    Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...

  7. 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 ...

  8. codeforces gym 100553I

    codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...

  9. CodeForces Gym 100213F Counterfeit Money

    CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...

随机推荐

  1. js document对象

    document对象可以通过多种方式获取: 最常见的一种情况是,你在文档的script脚本中直接使用document,这个document代表运行着该脚本的文档.(这个document和window. ...

  2. JavaScript操作DOM的那些坑

    js在操作DOM中存在着许多跨浏览器方面的坑,本文花了我将近一周的时间整理,我将根据实例整理那些大大小小的“坑”. DOM的工作模式是:先加载文档的静态内容.再以动态方式对它们进行刷新,动态刷新不影响 ...

  3. 看过的bootstrap书籍(附下载地址)

    http://yun.baidu.com/share/link?shareid=3820784617&uk=1008683945 以下书籍下载地址. <BootStrap入门教程> ...

  4. 【工作备忘】suricata

    因为工作遇到的困难,我向suricata的某个作者发送了邮件. On Wed, Sep 11, 2013 at 8:22 AM, likeyi <929812468@qq.com> wro ...

  5. PHPCURL直接访问JSONRPC服务

    <?php $ch = curl_init(); $url = 'http://localhost/jsonrpc?tm='.time().mt_rand (100,999); //参数是为了防 ...

  6. linux 新学到的命令

    nohup python -u /data/daemon/daemon/run.py & 使py程序可以在后台运行 nohup php a.php & 在linux平台上,要在后台运行 ...

  7. (window)Android Studio安装以及Fetching android sdk component information超时的解决方案

    转自:http://www.cnblogs.com/sonyi/p/4154797.html 在经过两年的开发之本后,Google 公司终于发布了 Android Studio 1.0,喜欢折腾的童鞋 ...

  8. Linux下的sort排序命令详解(一)

    1 sort的工作原理 sort将文件的每一行作为一个单位,相互比较,比较原则是从首字符向后,依次按ASCII码值进行比较,最后将他们按升序输出. [zookeeper@master rh]$ cat ...

  9. 一键安装GitLab7

    1. Install and configure the necessary dependencies If you install Postfix to send email please sele ...

  10. git会议分享

    git add . git add -A git add common.scss   只迁入某个文件 git pull h5 远程的:分支    这样就成功拉取一个新分支了 git push h5(远 ...