首页 技术 正文
技术 2022年11月12日
0 收藏 313 点赞 2,624 浏览 1418 个字

pid=1417″>题目链接~~>

做题感悟:比赛的时候用的广搜,然后高高兴兴的写完果断TLE 。做题的时候不管什么题都要用笔画一下,模拟几组数据,这样或许就AC了(做题经验,有心者谨记!)。

解题思路:贪心/规律

这题假设暴力找倍数的话必然超时(假设不超时就是数据问题了)。可是我们能够把它的倍数分类,把位数同样的倍数放在一类里,这样一共才18类,分类后仅仅须要找这一类中最小的元素代表这一类就能够了。问题就转化到如何找某一定位数某个数的字典序最小的倍数,我们知道最小字典序的那个数最前面假设最小的话仅仅能放1后面尽可能放 0 ,这样能够使达到的倍数尽量小。

          这里如果 k 的 6 位的倍数是 100xyz(这个数是超过 100000 的第一个倍数),那么这个数是否是最小的呢?我们让 100xyz 再加上 k (这里如果加上 k 之后位数不超 6 位),如果得到 100wpq。那么这个数的字典序一定比 100xyz的字典序大。由这个我们也能够知道 100xyz 一直加 k 得到的位数为 6 位的数的倍数一定都比 100xyz字典序大,这样我们能够得到答案的解。就是枚举超过 10,100 。1000 。10000 ……10^18 的第一个 k 的倍数取字典序最小的一个。

代码:

#include<iostream>
#include<sstream>
#include<map>
#include<cmath>
#include<fstream>
#include<queue>
#include<vector>
#include<sstream>
#include<cstring>
#include<cstdio>
#include<stack>
#include<bitset>
#include<ctime>
#include<string>
#include<cctype>
#include<iomanip>
#include<algorithm>
using namespace std ;
#define INT long long int
#define L(x) (x * 2)
#define R(x) (x * 2 + 1)
const int INF = 0x3f3f3f3f ;
const double esp = 0.0000000001 ;
const double PI = acos(-1.0) ;
const INT mod = 10000007 ;
const int MY = 1400 + 5 ;
const int MX = 18 + 5 ;
char ans[MX] ,str[MX] ;
INT n ,k ;
int judge(int x)
{
int ans = 0 ;
while(x)
{
x /= 10 ;
ans++ ;
}
return ans ;
}
int main()
{
while(scanf("%I64d%I64d" ,&n ,&k) ,n+k)
{
sprintf(ans ,"%lld" ,k) ;
int m = judge(k) ;
for(int i = m ;i <= 18 ; ++i) // 枚举每一种
{
INT temp = pow(10 ,i) ;
if(temp > n) break ;
if(temp % k == 0)
{
sprintf(str ,"%lld" ,temp) ;
if(strcmp(ans ,str) > 0)
strcpy(ans ,str) ;
}
INT tx = (temp/k+1)*k ;
if(tx > n) continue ;
sprintf(str ,"%lld" ,tx) ;
if(strcmp(ans ,str) > 0)
strcpy(ans ,str) ;
}
cout<<ans<<endl ;
}
return 0 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,497
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,910
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,744
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,498
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,135
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,299