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\)的最大公共 ...
随机推荐
- Java并发编程-关卡
CyclicBarrier 直译过来叫循环栅栏,它主要的方法就是一个:await().await() 方法没被调用一次,计数便会减少1,并阻塞住当前线程.当计数减至0时,阻塞解除,所有在此 Cycli ...
- OpenCV安装要点
OpenCV安装要点1.设置系统和用户环境变量PATH指向opencv\build\x86\vc10\bin或者opencv\build\x64\vc10\bin2.新建用户环境变量OpenCV指向o ...
- 事务处理: databse jdbc mybatis spring
事务的认识需要一个相当漫长的流程,慢慢在实践中理解,然后在强化相关理论基础. 数据库中的事务: 传统的本地事务处理都是依靠数据库自身事务处理能力,而事务本身是传统关系型数据库的基石.简单来说事务就是一 ...
- 【C#】构造函数的特点
1.它的函数名与类名相同:2.它可以重载:3.不能指定返回类型,即使是void也不行:4.虽然在一般情况下,构造函数不被显式调用,而是在创建对象时自动被调用.但是并不是不能被显示调用.有些时候是一定要 ...
- 在VS2103环境中集成Doxygen工具
自己已将学习了两三次了吧,差不多这次该总结一下: Doxygen是一种开源跨平台的,以类似JavaDoc风格描述的文档系统,完全支持C.C++.Java.Objective-C和IDL语言,部分支持P ...
- SCAU 10690 分面包
10690 分面包 时间限制:1000MS 内存限制:65535K 题型: 编程题 语言: 无限制 Description 在大一的时候,XCC还在stu union打酱油~~~~和十三还有奶子 ...
- phonegap 新窗口 inappbrowser插件
在Phonegap 开发过程中,需要调用外部网页,又要跳出白名单安全限制,可以使用 inappbrowser插件. http://plugins.cordova.io/#/package/org.ap ...
- labview图形和图表的类型
http://zone.ni.com/reference/zhs-XX/help/371361L-0118/lvconcepts/types_of_graphs_and_charts/ LabVIEW ...
- Labview中定时函数之间的区别
第一个定时函数(时间延迟):在VI中插入时间延迟,指定在运行调用VI之前延时的秒数.默认值为1.000. 第一个定时函数(等待(ms)):等待指定长度的毫秒数,并返回毫秒计时器的值.该函数进行异步系统 ...
- easyui问题小记
在easyui1.4.3版本中,(其他版本不知道是不是也是这样的),绑定在datagridview上面的数据最好不要是带有特殊符号的字段,不然会导致部分的属性不好用,比如这样的字段 START_DA ...