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\)的最大公共 ...
随机推荐
- 防范 DDoS 攻击的 15 个方法
为了对抗 DDoS(分布式拒绝服务)攻击,你需要对攻击时发生了什么有一个清楚的理解. 简单来讲,DDoS 攻击可以通过利用服务器上的漏洞,或者消耗服务器上的资源(例如 内存.硬盘等等)来达到目的.DD ...
- C#调用WebService实现天气预报 http://www.webxml.com.cn
C#调用WebService实现天气预报 2011-02-21 14:24:06 标签:天气预报 休闲 WebServices 职场 C# 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始 ...
- 【转】linux之tune2fs命令
转自:http://czmmiao.iteye.com/blog/1749232 tune2fs简介 tune2fs是调整和查看ext2/ext3文件系统的文件系统参数,Windows下面如果出现意外 ...
- cJSON学习笔记
1.JSON格式简述 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写,同时也易于机器解析和生成.它基于JavaScript(Standa ...
- 阿里巴巴2013年实习生笔试题B
阿里巴巴集团2013实习生招聘技术类笔试题(B) 一.单向选择题 1.在常用的网络协议中,___B__是面向连接的.有重传功能的协议. A. IP B. TCP C. UDP D. DXP 2.500 ...
- strcpy基本用法
C语言标准库函数strcpy,把从src地址开始且含有NULL结束符的字符串复制到以dest开始的地址空间. C语言函数 原型声明:extern char *strcpy(char* dest, co ...
- 【VC】VC工具栏图标合并工具(非tbcreator和visual toolbar)
VC开发难免会用到toolbar,在没有美工的时候,大部分时间我们只能自己上. 第一个方法:fireworks/photoshop平铺.现在的图片资源大多为背景透明的png图片,虽然fireworks ...
- Mapreduce执行过程分析(基于Hadoop2.4)——(二)
4.3 Map类 创建Map类和map函数,map函数是org.apache.hadoop.mapreduce.Mapper类中的定义的,当处理每一个键值对的时候,都要调用一次map方法,用户需要覆写 ...
- 第二百一十天 how can I 坚持
Node.js 服务器端JavaScript,单进程. 该如何学习啊,貌似学什么都学不深入. 纠结死了. 睡觉.
- 如何判断ios设备是否是高清屏幕
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2f) { CGRect winRect = [[UIScreen m ...