hdu5676 ztr loves lucky numbers(dfs)
链接
题意
定义幸运数为:只存在4和7且4和7数量相等的数,给出n,求比>=n的最小幸运数
做法
暴力搜出所有长度从2-18的幸运数,因为最多9个4,9个7,再大的话好像数组存不下只能特判了,然后二分找出比这个数大的那个数就行了
代码
#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL n[1100000];
int s4, s7, len, t;
void dfs(int s4, int s7, int len, LL num) {
if(s4 == len && len == s7) {
n[t++] = num;
return ;
}
if(s4 < len)
dfs(s4 + 1, s7, len, num * 10 + 4);
if(s7 < len)
dfs(s4, s7 + 1, len, num * 10 + 7);
}
int main() {
int T;
cin >> T;
t = 0;
for(int i = 1; i <= 9; i++)
dfs(0, 0, i, 0);
while(T--) {
LL num;
cin >> num;
int k = lower_bound(n, n + t, num) - n;
if(n[k])cout << n[k] << endl;
else {
for(int i = 0; i < 10; i++)cout << "4";
for(int i = 0; i < 10; i++)cout << "7";
cout << endl;
}
}
}
hdu5676 ztr loves lucky numbers(dfs)的更多相关文章
- hdu-5676 ztr loves lucky numbers(乱搞题)
题目链接: ztr loves lucky numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- hdu 5676 ztr loves lucky numbers(dfs+离线)
Problem Description ztr loves lucky numbers. Everybody knows that positive integers are lucky if the ...
- hdu 5676 ztr loves lucky numbers 打表+二分
ztr loves lucky numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/ ...
- HDU 5676 ztr loves lucky numbers (模拟)
ztr loves lucky numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/I Description ztr ...
- HDU 5676 ztr loves lucky numbers【DFS】
题目链接; http://acm.hdu.edu.cn/showproblem.php?pid=5676 题意: 由4和7组成的且4和7出现次数相同的数称为幸运数字,给定n,求不大于n的最大幸运数字. ...
- hdu 5676 ztr loves lucky numbers
题目链接:hdu 5676 一开始看题还以为和数位dp相关的,后来才发现是搜索题,我手算了下,所有的super lucky number(也就是只含数字4, 7且4, 7的数量相等的数)加起来也不过几 ...
- ztr loves lucky numbers 傻逼的我来了个大模拟
http://acm.hdu.edu.cn/showproblem.php?pid=5676 这题的正解因该是dfs的,但是有18个位,然后我一算,全排列的话,有18!个啊,那不是很大?但是有很多是相 ...
- ztr loves lucky numbers--hdu5676(DFS)
http://acm.hdu.edu.cn/showproblem.php?pid=5676 题目大意: 给你一个数 让你找比这数大并且只含4和7 并且4和7的个数一样 枚举从0到10的18次方之 ...
- hdu_5676_ztr loves lucky numbers
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5676 在这%一下安神,用了我没见过的黑科技next_permutation,至少我是今天才知道的 #i ...
随机推荐
- 输入输出流String间的转换
来自:http://wuhongyu.iteye.com/blog/806791 1.String to inputStream InputStream is = new ByteArrayInp ...
- cogs 983. [NOIP2003] 数字游戏
983. [NOIP2003] 数字游戏 ★☆ 输入文件:numgame.in 输出文件:numgame.out 简单对比时间限制:1 s 内存限制:128 MB 题目描述 丁丁最近沉 ...
- 杭电(hdu)ACM 1010 Tempter of the Bone
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- win7/WIN8.1(x64) 下使用MSDE WIN10不行
通过强制安装(使用管理员权限),手工启动服务的方式,能够在其win7 win81上安装并使用MSDE Microsoft SQL Server 2000 Service Pack 4 Desktop ...
- Javascript中数据实时推送
数据变化后前端需要更新,有几种方式:(参考http://www.xiaocai.name/post/cf1f9_7b6507) .利用setInterval函数,每隔n秒去异步拉取数据.对数据实时性要 ...
- 怎样又一次编译linux内核
linux作为自由软件.在广大爱好者的支持下,内核版本号不断更新. 新的内核修订了就得内核的bug,并添加了很多新的特性.假设用户须要使用这些新的特性或者依据自己的系统量身定做一个更高效或更稳定的内核 ...
- JDBC的使用(MySQL数据库)
一.MySQL数据库安装与数据库连接驱动程序设置 在官网中下载MySQL:https://dev.mysql.com/downloads/mysql/ 下载JDBC驱动包:https://dev.my ...
- pom.xml出现web.xml is missing and <failOnMissingWebXml> is set to true解决方案
提示信息应该能看懂.也就是缺少了web.xml文件,<failOnMissingWebXml>被设置成true了. 搜索了一下,Stack Overflow上的答案解决了问题,分享一下. ...
- 【POJ 3071】 Football
[题目链接] http://poj.org/problem?id=3071 [算法] 概率DP f[i][j]表示第j支队伍进入第i轮的概率,转移比较显然 [代码] #include <algo ...
- 框架-Eureka:初识 Eureka
ylbtech-框架-Eureka:初识 Eureka 1.返回顶部 1. 1.1. http://localhost:2100/ 1.2. 2. Eureka - Last N events 3. ...