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 ;
}

ACdream 1417 Numbers的更多相关文章

  1. ACdream 1214---矩阵连乘

    ACdream 1214---矩阵连乘 Problem Description You might have noticed that there is the new fashion among r ...

  2. acdream.LCM Challenge(数学推导)

     LCM Challenge Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit ...

  3. ACdream 1188 Read Phone Number (字符串大模拟)

    Read Phone Number Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Sub ...

  4. ACdream 1112 Alice and Bob(素筛+博弈SG函数)

    Alice and Bob Time Limit:3000MS     Memory Limit:128000KB     64bit IO Format:%lld & %llu Submit ...

  5. ACdream群赛1112(Alice and Bob)

    题意:http://acdream.info/problem?pid=1112 Problem Description Here  is Alice and Bob again ! Alice and ...

  6. POJ 1417 - True Liars - [带权并查集+DP]

    题目链接:http://poj.org/problem?id=1417 Time Limit: 1000MS Memory Limit: 10000K Description After having ...

  7. C. k-Amazing Numbers 解析(思維)

    Codeforce 1417 C. k-Amazing Numbers 解析(思維) 今天我們來看看CF1417C 題目連結 題目 略,請直接看原題. 前言 我實作好慢... @copyright p ...

  8. Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range

    在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...

  9. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

随机推荐

  1. 如何在CentOS 7上修改主机名

    如何在CentOS 7上修改主机名 在CentOS中,有三种定义的主机名:静态的(static),瞬态的(transient),和灵活的(pretty).“静态”主机名也称为内核主机名,是系统在启动时 ...

  2. SQL 关于有单引号数据更新的问题

    要把sql语句中包含有单引号的符号加入到数据库中的做法 )),''','123.com') 很简单就是加入id=''123''            0'0就可以写成'0''0'

  3. iOS中使用图片作为颜色的背景图

    Objective-C: [UIColor colorWithPatternImage:[UIImage imageNamed:@"jpg"]]; Swift: UIColor(p ...

  4. MySql中的变量定义(转)

    根据mysql手册,mysql的变量分为两种:系统变量和用户变量.但是在实际使用中,还会遇到诸如局部变量.会话变量等概念.根据个人感觉,mysql变量大体可以分为四种类型: 一.局部变量. 局部变量一 ...

  5. EcStore操作笔记

    1.去掉首页里面代码: <meta http-equiv="content-type" content="text/html; charset=utf-8" ...

  6. jQuery上传插件Uploadify 3.2使用

    Uploadify下载地址:http://www.uploadify.com/download/ 这里下载最新版的3.2的. 常用API描述: $(document).ready(function() ...

  7. linux 添加 $path

    # vim /etc/profile在文档最后,添加:export PATH="/usr/local/src/bin:$PATH"保存,退出,然后运行:#source /etc/p ...

  8. acdream暴力专场中的优美暴力

    F - 小晴天老师系列——苹果大丰收 Time Limit: 2000/1000MS (Java/Others)    Memory Limit: 128000/64000KB (Java/Other ...

  9. Flume笔记--source端监听目录,sink端上传到HDFS

    官方文档参数解释:http://flume.apache.org/FlumeUserGuide.html#hdfs-sink 需要注意:文件格式,fileType=DataStream 默认为Sequ ...

  10. oracle 数据库连接的四种方式

    Oracle Thin JDBC Driver驱动程序包名:ojdbc14.jar.ojdbc6.jar驱动程序类名: oracle.jdbc.driver.OracleDriverJDBC URL: ...