这道题目的意思是给你提供a, b, n 三个数

a为 输入的数字 ,你需要在a后面加n次 ,每次可以加0-9

但要保证每次加上去的那个数字能被b整除

不过数据规模有点大,用搜索会MLE(即使开了个开栈挂

#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0) using namespace std; typedef long long ll ;
typedef unsigned long long ull ;
typedef unsigned int uint ;
typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e- ;
const int N = ;
const int M = ;
const ll P = 10000000097ll ;
const int INF = 0x3f3f3f3f ; string a;
int b, n;
bool flag = false; string Multiply(string s,int x) //大数乘以整形数
{
reverse(s.begin(),s.end());
int cmp=;
for(int i=;i<s.size();i++)
{
cmp=(s[i]-'')*x+cmp;
s[i]=(cmp%+'');
cmp/=;
}
while(cmp)
{
s+=(cmp%+'');
cmp/=;
}
reverse(s.begin(),s.end());
return s;
} string Except(string s,int x) //大数除以整形数
{
int cmp=,ok=;
string ans="";
for(int i=;i<s.size();i++)
{
cmp=(cmp*+s[i]-'');
if(cmp>=x)
{
ok=;
ans+=(cmp/x+'');
cmp%=x;
}
else{
if(ok==)
ans+=''; //注意这里啊。才找出错误
}
}
return ans;
} void dfs(string a, int len){
if(flag) return;
if(n == len){
cout << a << endl;
flag = true;
return;
}
for(int i = ; i < ; ++i){
string num = a;
num.push_back('' + i);
string nn = Except(num, b);
string aa = Multiply(nn, b);
if(aa.compare(num) == ){
dfs(num, len + );
}
}
} int main(){
int i, j, k, t, m, numCase = ;
//string hh = "123";
//cout << atoi(hh.c_str());
while(cin >> a >> b >> n){
dfs(a, );
if(!flag){
cout << "-1" << endl;
} } return ;
}

MLE Code

解题思路:

非常巧妙,就是先在a后面加一个数字0-9如果能整除b,那么易得an后面跟无论多少个0都能整除b

所以就在an后面构造出(n-1)个0即可

无须搜索,超过30层容易爆空间~

//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0) using namespace std; typedef long long ll ;
typedef unsigned long long ull ;
typedef unsigned int uint ;
typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e- ;
const int N = ;
const int M = ;
const ll P = 10000000097ll ;
const int INF = 0x3f3f3f3f ; int main(){
int i, j, k, t, n, m, numCase = ;
int a, b, num;
//string hh = "123";
//cout << atoi(hh.c_str());
while(cin >> a >> b >> n){
bool flag = false;
for(i = ; i < ; ++i){
num = a * + i;
if(num % b == ){
a = num;
flag = true;
break;
}
}
if(!flag){
cout << - << endl;
return ;
}
cout << num;
for(i = ; i < n; ++i) cout << '';
cout << endl;
} return ;
}

CodeForces 260A Adding Digits的更多相关文章

  1. Codeforces Gym 100531D Digits 暴力

    Problem D. Digits 题目连接: http://codeforces.com/gym/100531/attachments Description Little Petya likes ...

  2. Codeforces 998D. Roman Digits 【打表找规律】

    <题目链接> 题目大意: 现在有无限个 1,5,10,50这四个数字,从中恰好挑选n个数字,问你这些数字的和总共有多少种不同的情况. 解题分析: 由于此题 n 的范围特别大,达到了1e9, ...

  3. Codeforces Round #158 (Div. 2)

    A. Adding Digits 枚举. B. Ancient Prophesy 字符串处理. C. Balls and Boxes 枚举起始位置\(i\),显然\(a_i \le a_j, 1 \l ...

  4. 1269 - Consecutive Sum

    1269 - Consecutive Sum    PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 64 MB ...

  5. Codeforces Round #379 (Div. 2) B. Anton and Digits 水题

    B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton fou ...

  6. [codeforces 509]C. Sums of Digits

    [codeforces 509]C. Sums of Digits 试题描述 Vasya had a strictly increasing sequence of positive integers ...

  7. CodeForces 1060 B Maximum Sum of Digits

    Maximum Sum of Digits You are given a positive integer n. Let S(x)S(x) be sum of digits in base 10 r ...

  8. Codeforces Round #277.5 (Div. 2)-C. Given Length and Sum of Digits...

    http://codeforces.com/problemset/problem/489/C C. Given Length and Sum of Digits... time limit per t ...

  9. 【codeforces 509C】Sums of Digits

    [题目链接]:http://codeforces.com/contest/509/problem/C [题意] 给你一个数组b[i] 要求一个严格升序的数组a[i]; 使得a[i]是b[i]各个位上的 ...

随机推荐

  1. bmfont制作数字

    http://blog.csdn.net/z104207/article/details/20136401

  2. HTTP协议中POST、GET、HEAD、PUT等请求方法以及一些常见错误 #Reprinted#

    请求方法是请求一定的Web页面的程序或用于特定的URL. 可选用下列几种: GET: 请求指定的页面信息,并返回实体主体. HEAD: 只请求页面的首部. POST: 请求服务器接受所指定的文档作为对 ...

  3. 转: 深入理解 AngularJS 的 Scope

      查看 DEMO.参考 StackOverflow. ng-switch ng-switch 的原型继承和 ng-include 一样.所以如果你需要对基本类型数据进行双向绑定,使用 $parent ...

  4. 模拟美萍加密狗--Rockey2虚拟狗(四)

    目录(?)[+]       首先,抱怨一下.学校个破网,似乎把我端口封了,死活分不上IP,也许是是我MAC改的太频繁了,有盗号嫌疑…… 然后,正文开始…… 其实虚拟狗几天前就写完了,可这几天上不了网 ...

  5. Lua学习笔记5:类及继承的实现

    -- Lua中类的实现 -------------------------------- 基类 ---------------------------- classBase = {x = 0,y = ...

  6. 初次接触VC++载入自己定义LIB 即静态链接

    分为两部分 第一部分  LIBproject 用来生成LIB文件 #ifndef _myfun #define _myfun int myfun(int x,int y) { return x+y; ...

  7. mac下配置cocos2d-x3.0

    今天看到3.0的正式版公布了,就马上荡下来试试3.0,以下记录下环境变量配置过程 打开用户文件夹下.bash_profile文件,配置环境 1.首先配置下android sdk,我的是在opt文件夹下 ...

  8. C++模板编程

    如何处理函数模板中的函数体? 预备知识补充: 按照c++的语言系统,普通函数及类的声明应该放在一个头文件中(通常是.h. .hpp..hh为扩展名)里: 而将其实现放在一个主代码文件中(通常以.c . ...

  9. 【在网页中获取截图数据】Chrome和Firefox下的实战经验

    [转载自我在segmentfault的专栏:https://segmentfault.com/a/1190000004584071] 最近在实现一个功能,需求如下: 前提:当前页面无弹窗 页面任意位置 ...

  10. iOS开发之第三方分享QQ分享,史上最新最全第三方分享QQ方式实现

    本文章源码地址: https://github.com/zhonggaorong/QQLoginDemo 项目搭建参考:  (包含QQ登录源码下载 . QQ sdk集成) http://blog.cs ...