Bestcoder #82 Div2 ztr loves lucky numbers(next_permutation)
来源:互联网 发布:c语言入门经典 编辑:程序博客网 时间:2024/04/30 22:04
题目链接:
Bestcoder #82 Div2 ztr loves lucky numbers
题意:
ztr喜欢幸运数字,他对于幸运数字有两个要求
1:十进制表示法下只包含4、7
2:十进制表示法下4和7的数量相等
比如47,474477就是
而4,744,467则不是
现在ztr想知道最小的但不小于n的幸运数字是多少?
有
分析:
比赛时我是当成字符串来处理,贼麻烦,而且WA了好多。。。
看了别人的代码,发现可以预处理出用next_permutation预处理出所有可能的答案组合,然后用lower_bound()查找即可。真好用啊。。。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <climits>#include <cmath>#include <ctime>#include <cassert>#define IOS ios_base::sync_with_stdio(0); cin.tie(0)using namespace std;const int MAX_N=1000010; typedef long long ll;int total,bit[30];ll ans[MAX_N];void init(){ total=0; for(int i=2;i<=18;i+=2){ for(int j=0;j<i/2;j++) { bit[j] = 4; } for(int j=i/2;j<i;j++) { bit[j] = 7; } do{ for(int j=0;j<i;j++){ ans[total]=ans[total]*10+bit[j]; } //printf("%lld\n",ans[total]); total++; }while(next_permutation(bit,bit+i)); } //printf("total=%d\n",total);}int main(){ IOS; freopen("B.in","r",stdin); init(); int T; ll n; cin>>T; while(T--){ cin>>n; if(n > 777777777444444444uLL){ printf("44444444447777777777\n"); continue; } int pos=lower_bound(ans,ans+total,n)-ans; cout<<ans[pos]<<endl; } return 0;}
0 0
- Bestcoder #82 Div2 ztr loves lucky numbers(next_permutation)
- BestCoder Round #82 ztr loves lucky numbers
- BestCoder Round #82 (div.2) -ztr loves lucky numbers(BFS)
- BestCoder #82 Div2 1001 ztr loves math(打表)
- ztr loves lucky numbers(二分,枚举)
- hdu ztr loves lucky numbers (暴搜)
- hdu5676 ztr loves lucky numbers
- HDU 5676 ztr loves lucky numbers(dfs+离线)——BestCoder Round #82(div.1 div.2)
- HDU 5756 ztr loves lucky numbers (dfs)
- hdoj ztr loves lucky numbers 5676 (dfs模拟)
- hdu 5676ztr loves lucky numbers(全排列函数)
- HDU 5676 ztr loves lucky numbers
- HDU 5676 ztr loves lucky numbers
- Hdu 5676 ztr loves lucky numbers
- hdu5676 ztr loves lucky numbers DFS+二分
- hdoj 5676 ztr loves lucky numbers 【二分】
- hdu5676 ztr loves lucky numbers 【打表】
- HDU 5676 ztr loves lucky numbers【DFS】
- Sources”参数中指定了多次。“Sources”参数不支持重复项
- FZU_1686_神龙的难题(DancingLinksX重复覆盖)
- handler消息模型原理
- Spring中ApplicationContext的事件机制
- Ubuntu14.04 Opencv2.4.9交叉编译
- Bestcoder #82 Div2 ztr loves lucky numbers(next_permutation)
- 监听应用的启动
- 理解矩阵
- 38- Majority Element
- 【LeetCode】Majority Element 解题报告
- 以太网之物理层
- HDU-4597 Play Game (区间DP)
- 【Unity3d】浅谈异步加载场景
- 【世界是自己的,与他人毫无关系】--杨绛