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. 紫书 习题 11-3 UVa 820 (最大流裸题)

    注意这道题是双向边, 然后直接套模板就ok了. #include<cstdio> #include<algorithm> #include<vector> #inc ...

  3. 网页里如何使用js屏蔽鼠标右击事件

    图片.png 在后台管理系统里面,遇到了这样的一个问题,右击ztree菜单,弹出修改界面,但是,现在确实这样的,右击默认弹出功能提示的框框,看上去似乎很影响自己想要的功能,只能禁用了,那么,网页里如何 ...

  4. Oracle 切割字符查询

    Oracle 切割字符查询 select * from view_psbaseinfo where DECODE('410782001125,411100000043', '', NULL, '410 ...

  5. [Javascript] String Padding in Javascript using padStart and padEnd functions

    ES2017 added two new string functions. They are padStart and padEndfunctions. In this lesson, we wil ...

  6. tomcat怎样禁止显示文件夹和文件列表

    查看原文:http://www.ibloger.net/article/300.html Tomcat禁止显示文件夹和文件列表 打开   tomcat的安装文件夹/conf/web.xml 文件 &l ...

  7. Caffe-python interface 学习|网络训练、部署、測试

    继续python接口的学习.剩下还有solver.deploy文件的生成和模型的測试. 网络训练 solver文件生成 事实上我认为用python生成solver并不如直接写个配置文件,它不像net配 ...

  8. bzoj1029: [JSOI2007]建筑抢修(堆+贪心)

    1029: [JSOI2007]建筑抢修 题目:传送门 题解: 一道以前就做过的水题(找个水题签个到嘛...) 很明显就是一道贪心题,这里我们用一个堆来维护 具体看代码吧,很容易YY所以不讲 代码: ...

  9. 人生之清单(list of life)

    人生要走走停停,想想记记,修修改改,再向前走.国家工程,公平正义,一腔热血,都很容易燃起来,热血起来. 1. 没得选,有得选,怎么办 没得选 原生家庭,自己怎么生,怎样的父母: 遇见谁,会有怎样的对白 ...

  10. Eval函数知识总结

    说道Json,我们先来聊聊eval 一.eval是什么?(解析器) eval是一个函数,看本质function  eval() { [native code] } 二.怎样使用eval? 语法:str ...