Gym - 100338E

题意:给你n,k问在1-n中能整出k的字典序最小的数。范围1018

思路:比较简单的贪心了,枚举10的幂m,然后加上k-m%k, 更新答案就可以了,数据一定要用unsigned long long,我就在这里挂了几次,查了半天。

 #include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define LL unsigned long long
#define eps 1e-8
#define INF 0x3f3f3f3f
#define MAXN 10005
using namespace std;
LL n, k;
LL m[];
//char s[25], res[25];
vector<char> s, t, res;
int main()
{
#ifdef ONLINE_JUDGE
freopen("numbers.in", "r", stdin);
freopen("numbers.out", "w", stdout);
#endif //ONLINE_JUDGE
m[] = ;
for (int i = ; i <= ; i++){
m[i] = m[i - ] * 10ULL;
}
while (~scanf("%I64d%I64d", &n, &k)){
if (n == && k == ) break;
for (int i = ; i <= ; i++){
LL p = m[i] % k == ? m[i] : m[i] + k - (m[i] % k);
if (p > n) break;
if (p % k != ) continue;
t.clear();
while (p != ){
t.push_back(p % 10ULL + '');
p /= 10ULL;
}
s.clear();
for (int j = t.size() - ; j >= ; j--){
s.push_back(t[j]);
}
if (i == ){
res = s;
continue;
}
bool flag = true;
for (int j = ; j < s.size(); j++){
if (res.size() < j + ){
flag = true;
break;
}
if (s[j] > res[j]){
flag = true;
break;
}
if (s[j] == res[j]) continue;
flag = false;
break;
}
if (flag) continue;
res = s;
}
for (int i = ; i < res.size(); i++){
printf("%c", res[i]);
}
printf("\n");
}
}

Gym - 100338E Numbers 贪心的更多相关文章

  1. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  2. Gym 101102J---Divisible Numbers(反推技巧题)

    题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...

  3. Codeforces Gym 100803C Shopping 贪心

    Shopping 题目连接: http://codeforces.com/gym/100803/attachments Description Your friend will enjoy shopp ...

  4. Gym 101775B - Scapegoat - [贪心+优先队列]

    题目链接:http://codeforces.com/gym/101775/problem/B Aori is very careless so she is always making troubl ...

  5. E - Third-Party Software - 2 Gym - 102215E (贪心)

    Pavel is developing another game. To do that, he again needs functions available in a third-party li ...

  6. POJ 2325 Persistent Numbers#贪心+高精度除法

    (- ̄▽ ̄)-* 这道题涉及高精度除法,模板如下: ]; ];//存储进行高精度除法的数据 bool bignum_div(int x) { ,num=; ;s[i];i++) { num=num*+ ...

  7. Codeforces.GYM101612E.Equal Numbers(贪心)

    题目链接 \(Description\) 给定\(n\)个数,每次可以将任意一个数乘上任意一个正整数. 求\(k\)次操作后,数列中数的种类最少可以是多少.对每个\(0\leq k\leq n\)输出 ...

  8. Gym 101201I Postman (贪心)

    题意:有个邮递员,要送信,每次最多带 m 封信,有 n 个地方要去送,每个地方有x 封要送,每次都到信全送完了,再回去,对于每个地方,可以送多次直到送够 x 封为止. 析:一个很简单的贪心,就是先送最 ...

  9. Gym - 100989H (贪心)

    After the data structures exam, students lined up in the cafeteria to have a drink and chat about ho ...

随机推荐

  1. PHP设计模式(三)抽象工厂模式(Abstract Factory)

    一.什么是抽象工厂模式 抽象工厂模式的用意为:给客户端提供一个接口,可以创建多个产品族中的产品对象 ,而且使用抽象工厂模式还要满足以下条件: 系统中有多个产品族,而系统一次只可能消费其中一族产品. 同 ...

  2. 【codeforces 816A】Karen and Morning

    [题目链接]:http://codeforces.com/contest/816/problem/A [题意] 让你一分钟一分钟地累加时间; 问多长时间以后是个回文串; [题解] reverse之后如 ...

  3. POJ 1161 Walls(最短路+枚举)

    POJ 1161 Walls(最短路+枚举) 题目背景 题目大意:题意是说有 n个小镇,他们两两之间可能存在一些墙(不是每两个都有),把整个二维平面分成多个区域,当然这些区域都是一些封闭的多边形(除了 ...

  4. Qt之字典划词

    简述 相信大家都用过词典吧!因为英语不太好...O(∩_∩)O~,所以经常进行划词翻译! 简述 实现 效果 源码 更多参考 实现 原理:鼠标移至某单词之上,获取鼠标位置,然后在对应位置进行取词,翻译! ...

  5. ios的notification机制是同步的还是异步的

    与javascript中的事件机制不同.ios里的事件广播机制是同步的,默认情况下.广播一个通知,会堵塞后面的代码: -(void) clicked { NSNotificationCenter *c ...

  6. 对象逆序列化报错:java.lang.ClassNotFoundException

    简单的想从保存的对象中又一次解析出对象.用了逆序列化,但是报错: java.lang.ClassNotFoundException: xxxxxxxxxxxx at java.net.URLClass ...

  7. Codeforces Round #249 (Div. 2) (模拟)

    C. Cardiogram time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  8. Linux下安装Mysql(RPM安装)

    一.去官网下载本次安装须要的mysql版本号.我们须要安装的是5.1版本号的且centos系统是64位的.所下面载的是MySQL-community-5.1.73-1.rhel5.x86_64.rpm ...

  9. ConfigurationSection

    https://msdn.microsoft.com/en-us/library/system.configuration.configurationsection(v=vs.110).aspx Re ...

  10. thinkphp5项目--个人博客(七)

    thinkphp5项目--个人博客(七) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...