hdu 5676 ztr loves lucky numbers
2016-06-07 23:09
393 查看
首先记录下来,然后二分。注意暴longlong的坑点
#include<bits/stdc++.h> using namespace std; #define ll long long int t ,cnt; const int maxn=1e6+10; ll a[maxn];ll n; void dfs(ll num,int sa,int sb){ if(sa+sb>=20) return ; if(sa==sb&&(sa!=0)){ a[cnt++]=num; } dfs(num*10+4,sa+1,sb); dfs(num*10+7,sa,sb+1); } int main(){ cin>>t;cnt=0; dfs(0,0,0); sort(a,a+cnt); // cout<<" = = = = == "<<a[cnt-1]<<endl; cout<<" cnt = "<<cnt<<endl; // for(int i=0;i<20;i++){ // cout<<a[i]<<" " ; // } // cout<<endl; while(t--){ scanf("%lld",&n); int ans=lower_bound(a,a+cnt,n)-a; if(ans==cnt){ puts("44444444447777777777"); } else{ cout<<" ans = "<<ans<<endl; cout<<a[ans]<<endl; } //\cout<<"ans = "<<a[ans]<<endl; } }
相关文章推荐
- 【HDU 5366】The mook jong 详解
- 【HDU 2136】Largest prime factor 详细图解
- 【HDU 1568】Fibonacci 数学公式 详解
- HDU 1568
- HDU1290
- HDU1568(Fobonacci公式)
- HDU ACM Step 2.2.2 Joseph(约瑟夫环问题)
- HDU 1405
- HDU 1297
- hdu 1205
- hdu 2087
- hdu 1016
- HDU 4898 The Revenge of the Princess’ Knight ( 2014 Multi-University Training Contest 4 )
- HDU 5592 ZYB's Premutation 线段树(查找动态区间第K大)
- HDU 5240 Exam (好水的题)
- HDU5237 Base64 大模拟
- HDU 1000
- HDU 1001
- HDU 1016 Prime Ring Problem
- HDU 1017 A Mathematical Curiosity