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 ...
随机推荐
- onunload与onbeforeunload事件解析 标签: 浏览器 2017-04-10 09:46 45人阅读 评论(0)
注:只测试了chrome和IE浏览器的表现情况 onunload事件 //JS Document window.onunload = onunload_message; function onunlo ...
- python爬虫07 | 有了 BeautifulSoup ,妈妈再也不用担心我的正则表达式了
我们上次做了 你的第一个爬虫,爬取当当网 Top 500 本五星好评书籍 有些朋友觉得 利用正则表达式去提取信息 太特么麻烦了 有没有什么别的方式 更方便过滤我们想要的内容啊 emmmm 你还别说 还 ...
- RabbitMQ学习总结(1)——基础概念详细介绍
一.基础概念详细介绍 1.引言 你是否遇到过两个(多个)系统间需要通过定时任务来同步某些数据?你是否在为异构系统的不同进程间相互调用.通讯的问题而苦恼.挣扎?如果是,那么恭喜你,消息服务让你可以很轻松 ...
- HDU4565 So Easy!
/* HDU4565 So Easy! http://acm.hdu.edu.cn/showproblem.php?pid=4565 数论 快速幂 矩阵快速幂 题意:求[(a+sqrt(b))^n ] ...
- 《 javascript 设计模式与开发实践 》 ---发布-订阅模式 代码小问题
定义公共事件: 删除事件优化:
- 【ACM】nyoj_139_我排第几个_201308062046
我排第几个时间限制:1000 ms | 内存限制:65535 KB 难度:3描述 现在有"abcdefghijkl”12个字符,将其所有的排列中按字典序排列,给出任意一种排列,说出这个排 ...
- sync_binlog=1
MySQL提供一个sync_binlog参数来控制数据库的binlog刷到磁盘上去. sync_binlog=0,表示MySQL不控制binlog的刷新,由文件系统自己控制它的缓存的刷新.这时候的性能 ...
- WebApplicationInitializer究 Spring 3.1之无web.xml式 基于代码配置的servlet3.0应用
本文转自http://hitmit1314.iteye.com/blog/1315816 大家应该都已经知道Spring 3.1对无web.xml式基于代码配置的servlet3.0应用.通过spri ...
- UVa 10465 Homer Simpson(DP 全然背包)
题意 霍默辛普森吃汉堡 有两种汉堡 一中吃一个须要m分钟 还有一种吃一个须要n分钟 他共同拥有t分钟时间 要我们输出他在尽量用掉全部时间的前提下最多能吃多少个汉堡 假设时间无法用 ...
- PL/SQL Developer自己主动补全SQL语句
快捷输入SQL语句,比如输入s,按下空格,自己主动替换成SELECT;再比如,输入se,按下空格, 自己主动替换成SELECT * FROM,很方便,节省了大量的时间去编写反复的SQL语句. 设置方法 ...