Codeforces 515C

CodeForces 515C

题意:定义f(1234)=1!*2!*3!*4!,现在给一个a,求x的最大整数,满足1,f(a)=f(x) ,在、x的十进制表示中不含1和0

思路:4!=2!*2!, 8!=2!*2!*2!*7!,6!=3!*5!,9!=7!*2!*3!*3!,尽量分成更多位

AC代码:

#include "iostream"
#include "string.h"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "set"
#include "map"
#include "algorithm"
#include "stdio.h"
#include "math.h"
#pragma comment(linker, "/STACK:102400000,102400000")
#define ll long long
#define endl ("\n")
#define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
#define mem(a,x) memset(a,x,sizeof(a))
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define ft (frist)
#define sd (second)
#define lrt (rt<<1)
#define rrt (rt<<1|1)
using namespace std;
const long long INF = 1e18+1LL;
const int inf = 1e9+1e8;
const int N=1e5+100;
const ll mod=1e9+7;

char s[20];
int n,ans[105];
int main(){
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>n>>s+1;
    int l=0;
    for(int i=1; i<=n; ++i){
        if(s[i]=='0' || s[i]=='1') continue;
        if(s[i]=='4'){
            ans[++l]=2,ans[++l]=2,ans[++l]=3;
        }
        else if(s[i]=='8'){
            ans[++l]=2,ans[++l]=2,ans[++l]=2,ans[++l]=7;
        }
        else if(s[i]=='6'){
            ans[++l]=3,ans[++l]=5;
        }
        else if(s[i]=='9'){
            ans[++l]=7,ans[++l]=2,ans[++l]=3,ans[++l]=3;
        }
        else ans[++l]=s[i]-'0';
    }
    sort(ans+1,ans+1+l);
    for(int i=l; i>=1; --i) cout<<ans[i];
    return 0;
}

 

posted on 2017-08-08 11:52  lazzzy  阅读(119)  评论(0编辑  收藏  举报

导航