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. hdu 2544

    #include <iostream> #include <cstdio> #define INF 9999999 //#define INF 0x3f3f3f3 using ...

  2. java分布式开发,什么是分布式开发

    就是同一个服务,把数据库的不同部分分开建立到不同的服务器上.以缓解数据库大量数据访问的压力.很多大公司的业务量比较大,每天的访问量都达到几百万上千万,甚至上亿的访问量,在访问量不是很大的情况下,是可以 ...

  3. Swift中简单的单例设计

    import Foundation class Test: NSObject { // 提供单例实例 static let shareInstance = Test() // 私有化构造方法 over ...

  4. [转]extern,static存储空间矛盾

    其实,这两个语句的位置不同,会出现不同的解释.这主要是由于 static 具有的两重意义所导致的: (1) 如果 static int foo; 这一句位于函数中,则 static 表示的是存储属性, ...

  5. ios nslog 打印字典为中文

    #import <Foundation/Foundation.h> @implementation NSDictionary (Log) - (NSString *)description ...

  6. 找不到请求的 .Net Framework Data Provider。可能没有安装。

    解决方法: 安装Microsoft SQL Server Compact 4.0. 安装Microsoft SQL Server Compact 4.0之后,程序运行正常. 问题的原因就是程序连接.s ...

  7. Hibernate+JPA

    参考链接:http://blog.163.com/hero_213/blog/static/398912142010312024809 近年来ORM(Object-Relational Mapping ...

  8. win7禁止自动使用浏览器打开FTP而是用资源管理器

    Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\ftp] @="URL:File Transfer Protocol" ...

  9. 浅谈 “空指针、野指针、void*”

            Author: JW. Zhou Date: 2014/7/2 一.空指针(0/NULL) 返回NULL和返回0是完全等价的,因为NULL和0都表示空指针,换句话说:空指针是什么,就是 ...

  10. android ftp案例分析

    使用方法: FTPClient client = new FTPClient(); client.connect("ftp.host.com", 8021); client.log ...