Gym 100531D Digits (暴力)
题意:给定一个数字,问你找 n 个数,使得这 n 个数各位数字之和都相等,并且和最小。
析:暴力,去枚举和是 1 2 3...,然后去选择最小的。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define debug puts("+++++")
//#include <tr1/unordered_map>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
//using namespace std :: tr1; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 50000 + 5;
const LL mod = 1e3 + 7;
const int N = 1e6 + 5;
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
inline int gcd(int a, int b){ return b == 0 ? a : gcd(b, a%b); }
inline int lcm(int a, int b){ return a * b / gcd(a, b); }
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int a[25], b[25]; bool judge(int x, int y){
int tmp = 0;
while(x){
tmp += x % 10;
x /= 10;
}
return tmp == y;
} int main(){
freopen("digits.in", "r", stdin);
freopen("digits.out", "w", stdout);
while(scanf("%d", &n) == 1){
memset(a, 0, sizeof a);
memset(b, 0, sizeof b);
for(int i = 1; i < 100000; ++i)
for(int j = 1; j <= 20; ++j)
if(a[j] < n && judge(i, j)){ b[j] += i; ++a[j]; }
int ans = INF;
for(int i = 1; i <= 20; ++i) if(a[i] == n){
ans = Min(ans, b[i]);
}
cout << ans << endl;
}
return 0;
}
Gym 100531D Digits (暴力)的更多相关文章
- Codeforces Gym 100531D Digits 暴力
Problem D. Digits 题目连接: http://codeforces.com/gym/100531/attachments Description Little Petya likes ...
- Codeforces Gym 100418K Cards 暴力打表
CardsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action? ...
- L - Ray in the tube Gym - 101911L (暴力)
---恢复内容开始--- You are given a tube which is reflective inside represented as two non-coinciding, but ...
- UVaLive 6585 && Gym 100299F Draughts (暴力+回溯)
题意:给定一个 10*10的矩阵,每一个W可以跳过一个B向对角走到#并把B吃掉,并且可以一直跳直到不能动为止,现在是W走的时候,问你最多吃几个B. 析:直接暴力+回溯,深搜就好. 代码如下: #pra ...
- Gym - 100203A Ariel 暴力+位运算
题意:第i种生物有k[i]个特征,分数是score[i],现在要参加竞赛,报出一种生物a,和一些特征h[i],参加竞赛的所有生物在这些h[i]上面的特征是一样的,a生物有h[i],则所有竞赛的生物都必 ...
- ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力
Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS Memory Limit:65536KB 64bit IO Fo ...
- ACM: Gym 100935G Board Game - DFS暴力搜索
Board Game Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Gym 100 ...
- Codeforces Gym 100803F There is No Alternative 暴力Kruskal
There is No Alternative 题目连接: http://codeforces.com/gym/100803/attachments Description ICPC (Isles o ...
- Codeforces Gym 100015H Hidden Code 暴力
Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...
随机推荐
- google play上获取apk文件
先说一种测试不通过的方法(chrome浏览器添加Direct APK downloader拓展程序),浪费了我很多的时间,结果发现根本用不了,记录一下过程给大家参考. 使用chrome浏览器,点击左上 ...
- Wannafly挑战赛2_D Delete(拓扑序+最短路+线段树)
Wannafly挑战赛2_D Delete Problem : 给定一张n个点,m条边的带权有向无环图,同时给定起点S和终点T,一共有q个询问,每次询问删掉某个点和所有与它相连的边之后S到T的最短路, ...
- python学习之-- redis模块操作 LIST
redis 模块操作之 List List 操作,在内存中按照一个name对应一个List来存储. lpush(name,values):在name对应的list中添加元素,每个新的元素都添加到列表的 ...
- java . 请在小于99999的正整数中找符合下列条件的数,它既是完全平方数,又有两位数字相同,如:144,676。
import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; //请在小于99999的正整数中找符合下列条件的 ...
- Spring中基于AOP的@AspectJ
以下内容引用自http://wiki.jikexueyuan.com/project/spring/aop-with-spring-framenwork/aspectj-based-aop-with- ...
- oracle数据库 SQL语句、内置函数大全
1.数值函数 函数 返回值 样例 显示 CEIL(n) 大于或等于数值n的最小整数 SELECT CEIL(10.6) FROM TABLE_NAME; 11 FLOOR(n) 小于等于数 ...
- POJ3264Balanced Lineup(最基础的线段树)
採用一维数组建树. (由于一维数组建的是全然二叉树,时间上比用孩子节点指针建树慢.只是基本能够忽略=-=) #include<iostream> #include<cstdio> ...
- MaterialImageView
https://github.com/zhaozhentao/MaterialImageView
- C语言变长数组data[0]总结
C语言变长数组data[0] 1.前言 今天在看代码中遇到一个结构中包含char data[0],第一次见到时感觉很奇怪,数组的长度怎么可以为零呢?于是上网搜索一下这样的用法的目的,发现在linux内 ...
- conda安装速度慢解决办法
注意,清华已经撤掉其ananconda源, 下面的方法已经失效,中科大源好像也不行,如果有解决办法烦请评论告诉我. conda config --add channels https://mirror ...