51nod 1435:位数阶乘

题目来源: CodeForces
基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题
 收藏
 关注

X是一个n位数的正整数 (x=a0a1...an1) 

现在定义 F(x)=i=0n1(ai!)  , 比如F(135)=1!*3!*5!=720.

我们给定一个n位数的整数X(至少有一位数大于1,X中可能有前导0),

然后我们去找一个正整数(s)符合以下条件:

1.这个数尽可能大,

2.这个数中不能含有数字0或1。

3.F(s)=F(x)


Input
每个测试数据输入共2行。
第一行给出一个n,表示x为中数字的个数。(1<=n<=15)
第二行给出n位数的正整数X(X中至少有一位数大于1)
Output
共一行,表示符合上述条件的最大值。
Input示例
4
1234
Output示例
33222

很好玩的一个题目,尽量对2到9的阶乘用尽可能多的其他阶乘表示。

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std;

int len;
int out1[100006];
int n,s_len;
long long num;

void check(int x)
{
	if(x==2)
	{
		out1[++n]=2;
	}
	else if(x==3)
	{
		out1[++n]=3;
	}
	else if(x==4)
	{
		out1[++n]=3;
		out1[++n]=2;
		out1[++n]=2;
	}
	else if(x==5)
	{
		out1[++n]=5;
	}
	else if(x==6)
	{
		out1[++n]=5;
		out1[++n]=3;
	}
	else if(x==7)
	{
		out1[++n]=7;
	}
	else if(x==8)
	{
		out1[++n]=7;
		out1[++n]=2;
		out1[++n]=2;
		out1[++n]=2;
	}
	else if(x==9)
	{
		out1[++n]=7;
		out1[++n]=3;
		out1[++n]=3;
		out1[++n]=2;
	}

}

void gao(string x)
{
	int i,len1=x.length();
	for(i=0;i<s_len;i++)
	{
		check(x[i]-'0');
	}
}

int main()
{	
	int i;
	string s;
	
	cin>>s_len>>s;
	
	n=0;
	gao(s);
	sort(out1+1,out1+1+n);
	
	for(i=n;i>=1;i--)
	{
		cout<<out1[i];
	}
	cout<<endl;
	return 0;
}



版权声明:本文为博主原创文章,未经博主允许不得转载。

posted on 2015-09-25 11:58  光速小子  阅读(150)  评论(0编辑  收藏  举报

导航