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. 怎样从外网访问内网Jetty?

    本地安装了一个Jetty,只能在局域网内访问,怎样从外网也能访问到本地的Jetty呢?本文将介绍具体的实现步骤. 准备工作 安装并启动Jetty 默认安装的Jetty端口是8080. 实现步骤 下载并 ...

  2. 4-20mA电流环路发送器入门(转)

    4-20mA电流环路发送器入门 作者:Collin Wells, 德州仪器精密模拟应用工程师 在现代工业控制系统中,4-20 mA电流环路发送器一直是在控制中心和现场传感器/执行器之间进行数据传输最为 ...

  3. 使用Ajax出现302 Moved Temporarily

    现象:在用ajax发送请求时,各种参数都对,地址也对,一直进error返回parse error. 使用浏览器发现ajax请求的header的响应码处:302 Moved Temporarily 百度 ...

  4. 用Intellij IDEA建mybatis案例

    用IDEA建mybatis案例 环境准备: 首先,建库建表(最好用navicat或sqlpro直接导) 然后打开IDEA, 1. java--->javaEE---> java app-- ...

  5. EDK II之USB协议栈的实现简介

    本文旨在简单介绍一下 UEFI中USB协议栈的代码框架: 主要包括: USB主控制器驱动(HCDI:EFI_USB2_HC_PROTOCOL) USB总线驱动(USBDI:EFI_USB_IO_PRO ...

  6. scrapy 下载图片 from cuiqingcai

    import scrapy class MzituScrapyItem(scrapy.Item): # define the fields for your item here like: # nam ...

  7. Python3 Pandas的DataFrame格式数据写入excle文件、json、html、剪贴板、数据库

    Python3 Pandas的DataFrame格式数据写入excle文件.json.html.剪贴板.数据库 一.DataFrame格式数据 Pandas是Python下一个开源数据分析的库,它提供 ...

  8. gdb远程debug A syntax error in expression, near `variable)'.

    今天调试有个linux环境的应用时,gdb提示A syntax error in expression, near `variable)'.,最后经查,gdb版本过低(比如7.2)或者源代码不匹配所致 ...

  9. Actions对Element的一些操作解析

    针对Chrome浏览器: 在自动化测试的编写中如果报出Element is not visible to click at xxxx point时,我会使用: new Actions(WebDrive ...

  10. topcoder srm 545 div1

    problem1 link 这个可以贪心地从前向后构造.假设当前已经的字符串为$S$,对于一个字符$c$来说,设将$c$加到$S$后得到的新串为$S^{'}$.那么如果$X+Y+Z \ge minIn ...