HDU 5676 贪心
2016-05-17 20:10
316 查看
#include <cstdio> #include <algorithm> using namespace std; const int maxn = 1E6 + 10; long long res[maxn], n, len, T; void dfs(int a, int b, long long x) { if (a == b && x) res[len++] = x; if (a < 9) dfs(a + 1, b, x * 10 + 4); if (b < 9) dfs(a, b + 1, x * 10 + 7); } int main(int argc, char const *argv[]) { dfs(0, 0, 0); sort(res, res + len); scanf("%lld", &T); while (T--) { scanf("%lld", &n); long long ans = lower_bound(res, res + len, n) - res; if (ans < len) printf("%lld\n", res[ans]); else printf("44444444447777777777\n"); } return 0; }
按位DFS,每一位只可能是4或7且4的个数与7的个数相等。
注意边界条件,10个4和10个7时超过ull,特判后输出。
相关文章推荐
- AFNetWorking实现GET、POST
- 抢购倒计时demo
- 修改环境变量为当前工作目录的.bat文件
- js中的this关键字详解
- linux shell script脚本数组的建立和使用
- 关于PHP+Mysql1045 Access denied for user错误解决办法——你可能想不到的
- 无线通信中的最大比合并(MRC)分析
- 写写Matlab的Turbo仿真实现吧
- Matlab的plot~各种颜色和线形
- XAMPP的安装及配置
- Matlab的var函数错了吗
- 讲一讲CSS的position/float/display都有哪些取值
- 第十二周
- WebLogic SSRF 漏洞 (简要翻译)
- 网络 协议与分层结构 的学习心得
- 大型网站架构系列:负载均衡详解(2)
- arm 汇编语言源码文件分析
- 【POJ3481】Double Queue——伸展树
- 【DirectX11】第六篇 纹理映射
- android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open