hdu_5676_ztr loves lucky numbers

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5676

在这%一下安神,用了我没见过的黑科技next_permutation,至少我是今天才知道的微笑

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cmath>
 4 #include<string>
 5 #include<set>
 6 #include<map>
 7 #include<vector>
 8 #include<queue>
 9 #include<algorithm>
10 #include<functional>
11 #define cl(a,b) memset(a,b,sizeof(a));
12 #define FFC(i,a,b) for(int i=a;i<=b;i++)
13 #define FFI(i,a,b) for(int i=a;i>=b;i--)
14 #define pb push_back
15 #define LL long long
16 using namespace std;
17 void fre(){freopen("c:\acm\input.txt","r",stdin);}
18 using namespace std;
19 int k[20];
20 LL f[100001];
21 int e[50];
22 int main(){
23     int cnt=0;
24     for(int i=2;i<=18;i+=2){
25         for(int j=0;j<i/2;j++)e[j]=4;
26         for(int j=i/2;j<i;j++)e[j]=7;
27         do{
28             for(int j=0;j<i;j++)f[cnt]=f[cnt]*10+e[j];
29             cnt++;
30         }while(next_permutation(e,e+i));
31     }//运用排列组合,将所有数算出来并保存
32     int t;
33     scanf("%d",&t);
34     while(t--){
35         LL n;
36         scanf("%I64d",&n);
37         if(n>777777777444444444LL){
38             printf("44444444447777777777
");
39             continue;
40         }
41         int pos=lower_bound(f,f+cnt,n)-f;
42         printf("%I64d
",f[pos]);
43     }
44     return 0;
45 }
View Code
原文地址:https://www.cnblogs.com/bin-gege/p/5696186.html