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. jquery 滚动加载

    <html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> < ...

  2. maven第三章 maven使用入门

    3.1编写pom groupId 一个项目名称 artifactId 子项目(模块)名称 version 开发中的版本,稳定的版本 name 项目名称,方便信息交流 http://news.cnblo ...

  3. asp.net微信开发第三篇----自定义会话管理

    和微信用户的沟通少不了,总觉得看起来微信官网后台管理中的会话回复消息有点呆板,所以我这里就自定义了一个会话管理功能,最终效果图如下: 因为我试使用富文本文件CKEDITOR来进行编写,你看到稳中可能会 ...

  4. java Byte.toString 方法与String.ValueOf(Byte)效率比较

    int times = 10000000; Byte[] li = new Byte[times]; for (int i = 0; i < times; i++) { li[i] = (byt ...

  5. 武汉科技大学ACM:1001: 谁不爱打牌

    Problem Description BobLee最近在复习考研,但是他也喜欢打牌(有谁不爱玩牌呢?).但是作为一名ACMER,斗地主显然满足不了他的兴趣,于是他和YYD一起YY出来了一个游戏规则, ...

  6. 一个Div在BOdy中上下左右居中

    在body中让一个DIv居中 上下左右 <body> <div style=" width:800px; height:500px; position:absolute; ...

  7. shell如何生成rpm包仓库列表文件的对比结果

    基本步骤: 1.切换至仓库目录RPM_LIST_DIR1和RPM_LIST_DIR2 2.ls列出仓库的rpm包文件并分别重定向至输出文件rpm_list_file1和rpm_list_file2 3 ...

  8. OpenStack点滴02-WSGI

    OpenStack对外提供REST API,那么REST API是如何建立起来的呢? OpenStack用了一种叫WSGI(Web Service Gateway Interface)的东西,WSGI ...

  9. UCOS 信号量的初值问题

    当 pend请求发出的时候信号量的值减1,当post的时候信号量的值加1,信号量的值0跟1分别是用来同步跟互斥的,什么是同步,什么是互斥呢...假设你把信号量的值设为0,有A,B连个任务,当A发出pe ...

  10. js 解析 json

    1.简单的json格式 { "user": [ { "name":"name1", "age":24, "se ...