您的位置:首页 > 其它

hdu_5676_ztr loves lucky numbers

2016-04-30 23:25 330 查看
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5676

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

#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<functional>
#define cl(a,b) memset(a,b,sizeof(a));
#define FFC(i,a,b) for(int i=a;i<=b;i++)
#define FFI(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define LL long long
using namespace std;
void fre(){freopen("c:\\acm\\input.txt","r",stdin);}
using namespace std;
int k[20];
LL f[100001];
int e[50];
int main(){
int cnt=0;
for(int i=2;i<=18;i+=2){
for(int j=0;j<i/2;j++)e[j]=4;
for(int j=i/2;j<i;j++)e[j]=7;
do{
for(int j=0;j<i;j++)f[cnt]=f[cnt]*10+e[j];
cnt++;
}while(next_permutation(e,e+i));
}//运用排列组合,将所有数算出来并保存
int t;
scanf("%d",&t);
while(t--){
LL n;
scanf("%I64d",&n);
if(n>777777777444444444LL){
printf("44444444447777777777\n");
continue;
}
int pos=lower_bound(f,f+cnt,n)-f;
printf("%I64d\n",f[pos]);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: