标签:style blog http color io os ar for strong
做题感悟:比赛的时候用的广搜,然后高高兴兴的写完果断TLE ,做题的时候无论什么题都要用笔画一下,模拟几组数据,这样也许就AC了(做题经验,有心者谨记!)。
解题思路:
模拟几组数据你就会发现 ,一定的位数第一个大于此位数的 k 的倍数就是最小的。如果再大一倍就必定比此数的字典序小,所以只要模拟大于10 ,100,1000,1000,的第一个倍数就可以了。
代码:
#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 ;
}
标签:style blog http color io os ar for strong
原文地址:http://blog.csdn.net/nyist_zxp/article/details/40212785