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. 教你如何修改CentOS系统上的时间

    直接看命令:

  2. [转载]SQL Server中的事务与锁

    了解事务和锁 事务:保持逻辑数据一致性与可恢复性,必不可少的利器. 锁:多用户访问同一数据库资源时,对访问的先后次序权限管理的一种机制,没有他事务或许将会一塌糊涂,不能保证数据的安全正确读写. 死锁: ...

  3. windows无法远程连接linux

    网络模式 修改对应的NAT模式,子网地址的前三位要与window,internet协议版本里的IP地址的前三位一致.

  4. mergesort_arithmetic_python

    def merge(a, b): c = [] h = j = 0 while j < len(a) and h < len(b): if a[j] < b[h]: c.append ...

  5. ==和equasl、hashmap原理(***)

    public class String01 { public static void main(String[] args) { String a="test"; String b ...

  6. 解决webgl使用canvas.toDataURL()没有内容的问题

    转的,记录一下,我还没有验证. 这个问题很好解决,就是在获取webgl对象的时候,多传入一个{preserveDrawingBuffer: true},然后在使用canvas.toDataURL()获 ...

  7. Linux使用退格键时出现^H解决方法

    以前在linux下执行脚本不注意输错内容需要删除时总是出现^H ,以前不知道真相的我没办法只有再重头运行一次脚本,后来发现其实时有解决办法的,所以记录一下. ^H不是H键的意思,是backspace. ...

  8. powermock+mockito+testng 单元测试pom文件

    0:Supported versions PowerMock version 1.7.0 and upper has experimental support of Mockito 2. A lot ...

  9. 初识wxPython

    wxPython是包装C++编写的wxWidgets跨平台的GUI组件 安装wxPython pip install wxpython import wx def load(event): file ...

  10. XX-net

    环境:win10企业版 #停用“ip helper”服务 net stop "ip helper" #启用“ip helper”服务 net start "ip help ...