这道题目的意思是给你提供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. Git使用方法记录(一)

    记录下git的基本使用方法,这里是以ubuntu14.04为例. 1,使用前的初始设置 git config –global user.name “FirstName LastName” git co ...

  2. Centos 安装docker报错

    错误信息: 安装报错:Transaction check error:  file /usr/lib/systemd/system/blk-availability.service from inst ...

  3. LintCode-丢失的第一个正整数

    题目描述: 给出一个无序的正数数组,找出其中没有出现的最小正整数. 样例 如果给出 [1,2,0], return 3 如果给出 [3,4,-1,1], return 2 挑战 只允许时间复杂度O(n ...

  4. Liunx 环境下vsftpd的三种实现方法(超详细参数)

    以下文章介绍Liunx 环境下vsftpd的三种实现方法 ftp://vsftpd.beasts.org/users/cevans/vsftpd-2.0.3.tar.gz,目前已经到2.0.3版本.假 ...

  5. BEANUTIL 对象转JSON

    package cn.com.softmap.cache.util; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutp ...

  6. VC编程之设置客户区背景图片

    在很多系统中出于美观的需要常常要设置背景图片.下面我介绍一种在客户区设置背景图片的简单方法. 1 .将背景bmp 图片导入到工程,资源ID 这里假设为 IDB_BITMAP1 2 .在视图类添加如下代 ...

  7. C# windows ce编程-----我的第一次

    最近公司要求开发抄表软件,软件分为PC端和手持终端(简称HHU),HHU是基于英文版的windows ce6.0操作系统,开发环境要求VS2005+SQLite数据库,开发语言为C#,因为是第一次基本 ...

  8. lightoj Again Array Queries

    1100 - Again Array Queries   PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 ...

  9. css优先级及权重值

    优先级: 外部样式表 内部样式表(位于<head>标签内部 内联样式(在HTML元素内部)优先权最高 内联样式>内部样式=外部样式(看具体引入位置,解析的先后) 权重值: 第一等:内 ...

  10. DevExpress ASP.NET 使用经验谈(8)-ASPxGridView自定义列和基本事件

    为演示本节示例,我们在原来Users表增加[性别Gender].[兴趣爱好Hobbies],[CreateTime创建时间],[ModifyTime]修改时间这4个字段, ALTER TABLE [d ...