ztr loves lucky numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1834    Accepted Submission(s): 707

Problem Description
ztr loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.

One day ztr came across a positive integer n. Help him to find the least super lucky number which is not less than n.

 
Input
There are T(1≤n≤105) cases

For each cases:

The only line contains a positive integer n(1≤n≤1018). This number doesn't have leading zeroes.

 
Output
For each cases
Output the answer
 
Sample Input
2
4500
47
 
Sample Output
4747
47
 
Source

思路:数总共没多少,打表即可,再最大的情况特判一下;

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e2+,M=1e6+,inf=1e9+;
const ll INF=5e17+,mod=1e9+; ///数组大小
int check(ll x)
{
int s=,q=;
while(x)
{
if(x%==)s++;
else q++;
x/=;
}
if(s==q)return ;
return ;
}
vector<ll>ans;
vector<ll>::iterator it;
void dfs(ll x)
{
if(x>INF)return;
if(check(x))ans.push_back(x);
dfs(x*+);
dfs(x*+);
}
int main()
{
dfs(),dfs();
sort(ans.begin(),ans.end());
int T;
scanf("%d",&T);
while(T--)
{
ll x;
scanf("%lld",&x);
it=lower_bound(ans.begin(),ans.end(),x);
if(it==ans.end())
printf("44444444447777777777\n");
else printf("%lld\n",*it);
}
return ;
}

hdu 5676 ztr loves lucky numbers 打表+二分的更多相关文章

  1. HDU 5676 ztr loves lucky numbers (模拟)

    ztr loves lucky numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/I Description ztr ...

  2. hdu 5676 ztr loves lucky numbers(dfs+离线)

    Problem Description ztr loves lucky numbers. Everybody knows that positive integers are lucky if the ...

  3. hdu 5676 ztr loves lucky numbers

    题目链接:hdu 5676 一开始看题还以为和数位dp相关的,后来才发现是搜索题,我手算了下,所有的super lucky number(也就是只含数字4, 7且4, 7的数量相等的数)加起来也不过几 ...

  4. HDU 5676 ztr loves lucky numbers【DFS】

    题目链接; http://acm.hdu.edu.cn/showproblem.php?pid=5676 题意: 由4和7组成的且4和7出现次数相同的数称为幸运数字,给定n,求不大于n的最大幸运数字. ...

  5. hdu-5676 ztr loves lucky numbers(乱搞题)

    题目链接: ztr loves lucky numbers  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536/65536 K ( ...

  6. ztr loves lucky numbers 傻逼的我来了个大模拟

    http://acm.hdu.edu.cn/showproblem.php?pid=5676 这题的正解因该是dfs的,但是有18个位,然后我一算,全排列的话,有18!个啊,那不是很大?但是有很多是相 ...

  7. hdu5676 ztr loves lucky numbers(dfs)

    链接 ztrloveslucky numbers 题意 定义幸运数为:只存在4和7且4和7数量相等的数,给出n,求比>=n的最小幸运数 做法 暴力搜出所有长度从2-18的幸运数,因为最多9个4, ...

  8. HDU 5677 ztr loves substring(Manacher+dp+二进制分解)

    题目链接:HDU 5677 ztr loves substring 题意:有n个字符串,任选k个回文子串,问其长度之和能否等于L. 题解:用manacher算法求出所有回文子串的长度,并记录各长度回文 ...

  9. HDU 5675 ztr loves math

    ztr loves math Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

随机推荐

  1. netperf 网络性能测试

    Netperf是一种网络性能的测量工具,主要针对基于TCP或UDP的传输.Netperf根据应用的不同,可以进行不同模式的网络性能测试,即批量数据传输(bulk data transfer)模式和请求 ...

  2. linux 查找locate find

    1.locate locate指令和find找寻档案的功能类似,但locate是透过update程序将硬盘中的所有档案和目录资料先建立一个索引数据库,在 执行loacte时直接找该索引,查询速度会较快 ...

  3. ssh-keygen 不是内部或外部命令

    如何处理呢? 1.找到Git/usr/bin目录下的ssh-keygen.exe(如果找不到,可以在计算机全局搜索) 2.属性-->高级系统设置-->环境变量-->系统变量,找到Pa ...

  4. 百度uid-generator源码

    https://github.com/baidu/uid-generator snowflake算法 uid-generator是基于Twitter开源的snowflake算法实现的. snowfla ...

  5. 第五章 CSS常用属性笔记

    1. span标签 突显,强调局部文字的作用. 2.字体样式 font-size: 字体大小 font-style:normal,italic(倾斜) font-weight:normal,bold( ...

  6. JQuery 实现 倒计时 按钮具体方法

    <head> <title>test count down button</title> <script src="http://ajax.aspn ...

  7. 20155201 网络攻防技术 实验八 Web基础

    20155201 网络攻防技术 实验八 Web基础 一.实践内容 Web前端HTML,能正常安装.启停Apache.理解HTML,理解表单,理解GET与POST方法,编写一个含有表单的HTML. We ...

  8. git博客好的例子

    01: https://github.com/Gaohaoyang/gaohaoyang.github.io 02: https://gaohaoyang.github.io/2018/06/01/a ...

  9. gcc,make,cmake

    1.gcc是GNU Compiler Collection(就是GNU编译器套件),也可以简单认为是编译器,它可以编译很多种编程语言(括C.C++.Objective-C.Fortran.Java等等 ...

  10. 从客户端(XXX)中检测到有潜在危险的Request.Form 值

    aspx 页面出现 [HttpRequestValidationException (0x80004005):从客户端(TextBox1="<?xml version="1. ...